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 managed rich text draft replacement
Barack Sokullu8ad6a45ae10c
diff --git a/docs/accessibility-tree-and-refs.md b/docs/accessibility-tree-and-refs.mdindex 51cd60812..bb141bea7 100644--- a/docs/accessibility-tree-and-refs.md+++ b/docs/accessibility-tree-and-refs.md@@ -163,6 +163,20 @@ input and Firefox uses trusted automation when enabled. DraftJS multiline inputuses a single public plain-text paste. See [rich-text input](rich-text-input.md)for editor detection, frame ownership and exact full-document readback.+Chrome selector typing also verifies the complete current selection before+replacing a DraftJS or ProseMirror document with one native `Input.insertText`.+It keeps the existing draft intact when selection cannot be proved. Deleting+first can mount a placeholder and disable Publish, invalidating preparation+before replacement text arrives. Explicit empty clears and generic editor+clearing retain native deletion and clear receipts; Firefox uses its existing+editor and companion paths.++Before each model decision, a sole visible dialog is captured by its subtree,+including the normal overlay context and any explicitly requested observation+scope. This avoids repeatedly formatting an occluded live timeline. Ordinary+AX reads retain full-page pagination, and only targets whose complete identity+was actually exposed in the current observation can receive action authority.+Rejects non-typeable input types (checkbox, radio, submit, file) with a clear error.### `set_field({ref_id, text, clear, submit})`diff --git a/docs/rich-text-input.md b/docs/rich-text-input.mdindex 1c902ca61..e0e6cafd9 100644--- a/docs/rich-text-input.md+++ b/docs/rich-text-input.md@@ -75,6 +75,11 @@ main boundaries. Installed Chrome extension tests also run the complete X andBluesky typing, local publication and fresh completion-proof flow. These areowned local fixtures; no live account is used or posted to.+Chrome replacement selection is checked independently of ProseMirror's paragraph+text reader, so headings, lists and blockquotes can also be replaced. Full native+selection must cover empty blocks and inline atoms as well as text; an intercepted+partial selection leaves the original application document intact.+When context verification or repeated page changes prevent the next action,the task shows a specific explanation and Give up / Retry choices. Retry keepscompleted progress and verifies the current page again using the normal checks.@@ -82,6 +87,6 @@ completed progress and verifies the current page again using the normal checks.Run the focused suite with:```sh-node --test test/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/draftjs-text.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/contenteditable-beforeinput.mjs+node --test test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/draftjs-text.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/contenteditable-beforeinput.mjsnpm run test:composer-context```diff --git a/package.json b/package.jsonindex 091617ab6..5c4e8fcad 100644--- a/package.json+++ b/package.json@@ -55,8 +55,8 @@"benchmark:relevance": "node scripts/benchmark-offline-relevance.mjs --verbose","test:social-contract": "node --test test/social-publish-contract.mjs","test:social-contract:dom": "node test/social-publish-contract-dom.mjs",- "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/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/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.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-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.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/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-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/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.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 test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-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/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/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs",- "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.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/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/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/chat-steering.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-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.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/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-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/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.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 test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-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/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/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs",+ "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/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-passive-progress.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs && node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs","test:chat-steering": "node --test test/chat-steering.mjs test/chat-steering-ui.mjs","test:rich-text-dom": "node test/ui-content-lifecycle.mjs --dom","test:firefox-bidi": "node --test test/firefox-bidi.mjs test/firefox-full-page-screenshot.mjs",@@ -87,7 +87,7 @@"test:chat-draft-recovery": "node --test test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs && node test/quality/native-chat-presubmit-mv3.mjs","test:upload-owner": "node --test test/page-monitor-upload-owner.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: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/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/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/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/chat-steering.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-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs",+ "test:shard:runtime-unit": "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/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/chat-steering.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-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/completion-current-execution-evidence.mjs","test:shard:browser-a": "node test/bot-memory-dom.mjs && node test/bot-memory-click-dom.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/native-button-preparation.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-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/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.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:shard:browser-b1": "node test/message-recipient-upload.mjs && node --test test/message-recipient-whatsapp.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-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/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 6ca5bd0a6..55b4575d5 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -21201,6 +21201,37 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn sources;}+ async _socialDraftClarificationArgs(tabId, args) {+ const guard = this._planExecutionGuards.get(tabId), social = guard?.socialPublication;+ const target = social?.clarificationTarget;+ const question = String(args?.question || ''), options = Array.isArray(args?.options) ? args.options : [];+ if (!guard?.enabled || social?.contract?.status !== 'clarify' || !target+ || target.taskKey !== guard.taskKey || guard.taskKey !== this._progressTaskKeyHash(tabId)+ || !question.includes('\\') || !options.some(option => typeof option === 'string' && option.includes('\\'))+ || args?.purpose || this._checkAbort(tabId) || this._hasPendingSteering(tabId)) return args;+ let fresh;+ try {+ if (await this._currentUrl(tabId) !== target.pageUrl) return args;+ fresh = await this._detectLikelySubmitAction(tabId, target.tool, target.args);+ } catch { return args; }+ if (this._planExecutionGuards.get(tabId) !== guard || guard.socialPublication !== social+ || social.needsRecompile || this._checkAbort(tabId) || this._hasPendingSteering(tabId)+ || fresh?.isSubmit !== true || fresh.publicationControl !== true+ || fresh.publicationSnapshot?.complete !== true || fresh.publicationSnapshot.posts?.length !== 1+ || fresh.publicationSnapshot.posts[0]?.complete !== true) return args;+ const body = fresh.publicationSnapshot.posts[0].bodyText;+ if (typeof body !== 'string' || !body) return args;+ const encoded = JSON.stringify(body).slice(1, -1);+ if (encoded === body || !question.includes(encoded)+ || !options.some(option => typeof option === 'string' && option.includes(encoded))) return args;+ // Only correct the exact JSON representation of this freshly observed+ // draft before displaying it. The page supplies a proposal, never intent;+ // the human's displayed selection becomes the authoritative answer.+ return { ...args, question: question.split(encoded).join(body),+ options: options.map(option => typeof option === 'string' ? option.split(encoded).join(body) : option),+ require_explicit_answer: true };+ }+_recordSocialPublicationClarification(tabId, guard, question, answer, source) {if (!guard?.enabled || this._planExecutionGuards.get(tabId) !== guard|| !['user', 'option'].includes(source) || !question || !answer) return;@@ -21622,6 +21653,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (social?.needsRecompile || !action || action.platform !== live.adapterName|| !publicationProgress(social?.contract, social?.outcomes).eligible.includes(action.id)) {if (social?.contract?.status === 'clarify') {+ if (!Number.isFinite(args.x) && !Number.isFinite(args.y) && (args.ref_id || args.selector)) {+ social.clarificationTarget = { taskKey: guard.taskKey, pageUrl, tool: name, args: structuredClone(args) };+ }return blocked('Publication details are unresolved: ' + social.contract.reason+ ' Resolve the missing detail, not just permission. If the post text is missing, include the complete proposed text in one clarification; a yes/no approval without that text cannot supply it.');}@@ -30633,6 +30667,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaiconst unchangedPreparation = result[TRUSTED_FIELD_PREPARATION_UNCHANGED];if (unchangedPreparation?.tabId === tabId && unchangedPreparation.tool === name&& unchangedPreparation.refId === args.ref_id+ && (!Object.hasOwn(unchangedPreparation, 'selector') || unchangedPreparation.selector === args.selector)&& result.success === false && result.verified === false) {const unchangedResult = { ...result };delete unchangedResult[TRUSTED_FIELD_PREPARATION_UNCHANGED];@@ -38226,6 +38261,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai// the configurable auto-timeout elapses (first option / timeout note).// Permission and form-submit prompts use separate helpers and never time out.if (name === 'clarify') {+ args = await this._socialDraftClarificationArgs(tabId, args);const clarificationGuard = this._planExecutionGuards.get(tabId);const question = String(args?.question || '').trim();if (!question) {@@ -43836,6 +43872,9 @@ If the user has already named or confirmed this exact recipient, do NOT ask agaideadlineAt: Number(CONTENT_ACTION_SIGNAL_DEADLINES.get(earlyCdpAbortSignal)?.deadlineAt) || 0,deadlineError: CONTENT_ACTION_SIGNAL_DEADLINES.get(earlyCdpAbortSignal)?.error || null,beforeDispatch: markEarlyCdpDispatched,+ onUnchangedPreparation: failure => {+ failure[TRUSTED_FIELD_PREPARATION_UNCHANGED] = { tabId, tool: 'type_text', refId: args.ref_id, selector: args.selector };+ },},);throwIfEarlyCdpAborted();diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex afc41180b..c3e546140 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -8,7 +8,7 @@ const { validateUploadFile, observedFileViewerResource, source: FILE_UPLOAD_POLI*/import { combineImages } from './image-utils.js';-import { beforePageAgentDispatch, hasPageAgentDispatchOwner, pageFeedbackPendingResult } from '../agent/page-feedback.js';+import { beforePageAgentDispatch, capturePageAgentInputCompletion, hasPageAgentDispatchOwner, pageFeedbackPendingResult } from '../agent/page-feedback.js';const SELECTOR_SCROLL_DISPATCH_SOURCE = `const beforeSelectorScroll = (element, guard) => {@@ -5364,6 +5364,62 @@ export class CDPClient {}}+ async _managedTextReplacementSelection(tabId, selector, nodeId) {+ let objectId = null, objectGroup = null;+ try {+ if (Number.isInteger(nodeId) && nodeId > 0) {+ objectId = (await this.sendCommand(tabId, 'DOM.resolveNode', { nodeId }))?.object?.objectId;+ } else {+ const targets = await this.querySelectorPierce(tabId, selector);+ objectGroup = targets?.objectGroup;+ if (targets?.objectIds?.length === 1) objectId = targets.objectIds[0];+ }+ if (!objectId) return null;+ const result = await this.sendCommand(tabId, 'Runtime.callFunctionOn', {+ objectId, returnByValue: true,+ functionDeclaration: `function () {+ const draftJs = (${isDraftJsEditor.toString()})(this);+ if (!draftJs && !this.classList.contains('ProseMirror')) return { managedEditor: false };+ const failed = { managedEditor: true, selected: false };+ if (!this.isConnected || !this.isContentEditable || this.getAttribute('aria-readonly') === 'true') return failed;+ const root = this.getRootNode(), view = this.ownerDocument.defaultView;+ if (root.activeElement !== this) return failed;+ const selection = root.getSelection?.() || view.getSelection();+ if (selection?.rangeCount !== 1) return failed;+ const range = selection.getRangeAt(0);+ if (!this.contains(range.startContainer) || !this.contains(range.endContainer)) return failed;+ if (draftJs && (${readDraftJsText.toString()})(this) === null) return failed;+ // Selection coverage is structural, independent of the text reader's+ // supported block formats. Empty blocks and inline atoms also occupy+ // document positions even though they contribute no text nodes.+ const walker = this.ownerDocument.createTreeWalker(this, view.NodeFilter.SHOW_TEXT | view.NodeFilter.SHOW_ELEMENT);+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {+ if (node.nodeType === 3) {+ if (node.length && (range.comparePoint(node, 0) !== 0 || range.comparePoint(node, node.length) !== 0)) return failed;+ continue;+ }+ const placeholder = node.tagName === 'BR' && (draftJs+ || node.classList.contains('ProseMirror-trailingBreak'));+ if (placeholder) {+ if (!node.parentElement.textContent && range.comparePoint(node.parentNode,+ Array.prototype.indexOf.call(node.parentNode.childNodes, node)) !== 0) return failed;+ } else if (node.getAttribute('contenteditable') === 'false' || /^(BR|IMG|HR|INPUT|VIDEO|AUDIO|IFRAME)$/.test(node.tagName)) {+ const index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);+ if (range.comparePoint(node.parentNode, index) !== 0 || range.comparePoint(node.parentNode, index + 1) !== 0) return failed;+ } else if (!node.childNodes.length && /^(block|list-item|table-cell|flow-root|flex|grid)$/.test(view.getComputedStyle(node).display)+ && range.comparePoint(node, 0) !== 0) return failed;+ }+ return { managedEditor: true, selected: true };+ }`,+ });+ return result?.result?.value || null;+ } catch { return null; }+ finally {+ if (objectGroup) await this.sendCommand(tabId, 'Runtime.releaseObjectGroup', { objectGroup }).catch(() => null);+ else if (objectId) await this.releaseObject(tabId, objectId);+ }+ }+/*** Prove a text edit landed. Returns `true` when proven and `null` when it* could not be proven — never `false`.@@ -6159,9 +6215,12 @@ export class CDPClient {const clearReceipt = clear ? await this.captureTextClearReceipt(tabId, { selector, nodeId: info.nodeId }) : null;try {- // Clear existing content if requested. Use Select All + Delete via key events- // so the page observes proper input events.+ // Keep managed replacements atomic; explicit empty clears and generic+ // fields still use the native Select All + Delete path.if (clear) {+ const replacement = insertionText !== ''+ ? await this._managedTextReplacementSelection(tabId, selector, info.nodeId) : null;+ throwIfAborted();try {// Select allconst selectAllModifiers = await this.selectAllModifier(tabId);@@ -6170,10 +6229,11 @@ export class CDPClient {await dispatchKeyPress({key: 'a', code: 'KeyA', modifiers: selectAllModifiers, windowsVirtualKeyCode: 65, commands: ['selectAll'],});- // Delete selection- await dispatchKeyPress({- key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,- });+ if (replacement?.managedEditor !== true) {+ await dispatchKeyPress({+ key: 'Delete', code: 'Delete', windowsVirtualKeyCode: 46,+ });+ }} catch (e) {if (e?.code === 'page_feedback_pending') throw e;if (actionExpired()) throwIfAborted();@@ -6186,7 +6246,24 @@ export class CDPClient {error: `Could not safely clear the text field: ${e?.message || String(e)}`,};}- const cleared = await this.verifyTextEntry(tabId, {+ const selectedReplacement = replacement?.managedEditor === true+ ? await this._managedTextReplacementSelection(tabId, selector, info.nodeId) : null;+ throwIfAborted();+ if (replacement?.managedEditor === true && selectedReplacement?.selected !== true) {+ const unchanged = typeof beforeSignature === 'string' && await this.textEntrySignature(tabId, {+ selector, nodeId: info.nodeId,+ }) === beforeSignature;+ throwIfAborted();+ const failure = { success: false, dispatched: true, verified: false, mutationMayHaveOccurred: !unchanged,+ outcomeUnknown: !unchanged, retryable: unchanged, repeatBlocked: !unchanged,+ recoveryRequired: unchanged ? 'fresh_tree' : 'verify_or_restore_field',+ error: 'The original editor could not be proven fully selected. No replacement text was inserted. Re-observe before trying again.' };+ if (unchanged && typeof resolveOptions.onUnchangedPreparation === 'function') resolveOptions.onUnchangedPreparation(failure);+ return failure;+ }+ // Managed editors replace the proved selection atomically. Deleting first+ // mounts placeholders and changes Post state before the insertion.+ const cleared = replacement?.managedEditor === true ? true : await this.verifyTextEntry(tabId, {selector,nodeId: info.nodeId,text: '',@@ -6205,6 +6282,10 @@ export class CDPClient {}}+ // Capture this exact operation before input changes the editor. Only its+ // acknowledged, verified write may finish; lost input retains uncertainty.+ const inputGuard = await beforePageAgentDispatch(globalThis.chrome, tabId, { kind: 'input', selector, fenceOnly: true });+ const finishInput = capturePageAgentInputCompletion(globalThis.chrome, tabId, inputGuard);// Type via Input.insertText — atomic, fires beforeinput/input correctly.try {dispatched = true;@@ -6239,6 +6320,11 @@ export class CDPClient {error: 'Text was inserted, but the complete settled field value could not be verified exactly.',};}+ if (finishInput && !await finishInput()) {+ return { success: false, dispatched: true, verified: false, outcomeUnknown: true,+ mutationMayHaveOccurred: true, retryable: false,+ error: 'The editor value was verified, but its owned input operation could not be completed. Re-observe before acting.' };+ }return {success: true,verified: true,diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex 2a13578a4..b559876d3 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -1524,7 +1524,15 @@// Reserve space for the requested owner's current identity evidence.// AX omits some visible generic wrappers (for example recipient chips).const contextual = priorityTarget || validObservationRoot;- const tree = window.__generateAccessibilityTree('visible', 15, contextual ? 4000 : 6000);+ const dialogs = [...document.querySelectorAll('dialog,[role="dialog"],[role="alertdialog"]')];+ const visibleDialogs = dialogs.length <= 32 ? dialogs.filter(node => visible(node)+ && !node.closest('[aria-hidden="true"]')) : [];+ const dialogRoots = visibleDialogs.filter(node => !visibleDialogs.some(other => other !== node && other.contains(node)));+ // A sole open dialog owns the current observation. The normal AX+ // reader still handles the full page and explicitly requested scopes;+ // model capture must not repeatedly format its occluded live timeline.+ const dialogRef = dialogRoots.length === 1 ? window.__wb_ax_ref?.(dialogRoots[0]) : undefined;+ const tree = window.__generateAccessibilityTree('visible', 15, contextual ? 4000 : 6000, dialogRef);if (!tree || tree.error || typeof tree.pageContent !== 'string') throw new Error('unavailable');page = { success: true, ...tree, pageContent: boundedTreeText(tree, contextual ? 4000 : 6000), url: location.href };if (validObservationRoot) {@@ -1686,6 +1694,10 @@};const captureTarget = node => {if (!(node instanceof Element) || ignored(node) || seen.has(node) || seen.size >= MODEL_SCAN_LIMIT) return;+ // Unobserved nodes cannot receive a model certificate. Avoid rebuilding+ // their full owner footprints across a large live page; hidden file+ // inputs still need the existing structural owner proof.+ if (page && !publicNodes.has(node) && !(node.tagName === 'INPUT' && node.type === 'file')) return;seen.add(node);const footprint = targets.size < MODEL_TARGET_LIMIT ? actionFootprint(node, node === readonlyPreparation?.target ? readonlyPreparation : null) : null;if (footprint && !observedFootprint(footprint)) return;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex c06b52b05..88a2bfc5c 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -18847,6 +18847,37 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn sources;}+ async _socialDraftClarificationArgs(tabId, args) {+ const guard = this._planExecutionGuards.get(tabId), social = guard?.socialPublication;+ const target = social?.clarificationTarget;+ const question = String(args?.question || ''), options = Array.isArray(args?.options) ? args.options : [];+ if (!guard?.enabled || social?.contract?.status !== 'clarify' || !target+ || target.taskKey !== guard.taskKey || guard.taskKey !== this._progressTaskKeyHash(tabId)+ || !question.includes('\\') || !options.some(option => typeof option === 'string' && option.includes('\\'))+ || args?.purpose || this._checkAbort(tabId) || this._hasPendingSteering(tabId)) return args;+ let fresh;+ try {+ if (await this._currentUrl(tabId) !== target.pageUrl) return args;+ fresh = await this._detectLikelySubmitAction(tabId, target.tool, target.args);+ } catch { return args; }+ if (this._planExecutionGuards.get(tabId) !== guard || guard.socialPublication !== social+ || social.needsRecompile || this._checkAbort(tabId) || this._hasPendingSteering(tabId)+ || fresh?.isSubmit !== true || fresh.publicationControl !== true+ || fresh.publicationSnapshot?.complete !== true || fresh.publicationSnapshot.posts?.length !== 1+ || fresh.publicationSnapshot.posts[0]?.complete !== true) return args;+ const body = fresh.publicationSnapshot.posts[0].bodyText;+ if (typeof body !== 'string' || !body) return args;+ const encoded = JSON.stringify(body).slice(1, -1);+ if (encoded === body || !question.includes(encoded)+ || !options.some(option => typeof option === 'string' && option.includes(encoded))) return args;+ // Only correct the exact JSON representation of this freshly observed+ // draft before displaying it. The page supplies a proposal, never intent;+ // the human's displayed selection becomes the authoritative answer.+ return { ...args, question: question.split(encoded).join(body),+ options: options.map(option => typeof option === 'string' ? option.split(encoded).join(body) : option),+ require_explicit_answer: true };+ }+_recordSocialPublicationClarification(tabId, guard, question, answer, source) {if (!guard?.enabled || this._planExecutionGuards.get(tabId) !== guard|| !['user', 'option'].includes(source) || !question || !answer) return;@@ -19268,6 +19299,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (social?.needsRecompile || !action || action.platform !== live.adapterName|| !publicationProgress(social?.contract, social?.outcomes).eligible.includes(action.id)) {if (social?.contract?.status === 'clarify') {+ if (!Number.isFinite(args.x) && !Number.isFinite(args.y) && (args.ref_id || args.selector)) {+ social.clarificationTarget = { taskKey: guard.taskKey, pageUrl, tool: name, args: structuredClone(args) };+ }return blocked('Publication details are unresolved: ' + social.contract.reason+ ' Resolve the missing detail, not just permission. If the post text is missing, include the complete proposed text in one clarification; a yes/no approval without that text cannot supply it.');}@@ -34763,6 +34797,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// / timeout note). Permission and form-submit prompts use separate// helpers and never time out.if (name === 'clarify') {+ args = await this._socialDraftClarificationArgs(tabId, args);const clarificationGuard = this._planExecutionGuards.get(tabId);const question = String(args?.question || '').trim();if (!question) {diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex 2a13578a4..b559876d3 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -1524,7 +1524,15 @@// Reserve space for the requested owner's current identity evidence.// AX omits some visible generic wrappers (for example recipient chips).const contextual = priorityTarget || validObservationRoot;- const tree = window.__generateAccessibilityTree('visible', 15, contextual ? 4000 : 6000);+ const dialogs = [...document.querySelectorAll('dialog,[role="dialog"],[role="alertdialog"]')];+ const visibleDialogs = dialogs.length <= 32 ? dialogs.filter(node => visible(node)+ && !node.closest('[aria-hidden="true"]')) : [];+ const dialogRoots = visibleDialogs.filter(node => !visibleDialogs.some(other => other !== node && other.contains(node)));+ // A sole open dialog owns the current observation. The normal AX+ // reader still handles the full page and explicitly requested scopes;+ // model capture must not repeatedly format its occluded live timeline.+ const dialogRef = dialogRoots.length === 1 ? window.__wb_ax_ref?.(dialogRoots[0]) : undefined;+ const tree = window.__generateAccessibilityTree('visible', 15, contextual ? 4000 : 6000, dialogRef);if (!tree || tree.error || typeof tree.pageContent !== 'string') throw new Error('unavailable');page = { success: true, ...tree, pageContent: boundedTreeText(tree, contextual ? 4000 : 6000), url: location.href };if (validObservationRoot) {@@ -1686,6 +1694,10 @@};const captureTarget = node => {if (!(node instanceof Element) || ignored(node) || seen.has(node) || seen.size >= MODEL_SCAN_LIMIT) return;+ // Unobserved nodes cannot receive a model certificate. Avoid rebuilding+ // their full owner footprints across a large live page; hidden file+ // inputs still need the existing structural owner proof.+ if (page && !publicNodes.has(node) && !(node.tagName === 'INPUT' && node.type === 'file')) return;seen.add(node);const footprint = targets.size < MODEL_TARGET_LIMIT ? actionFootprint(node, node === readonlyPreparation?.target ? readonlyPreparation : null) : null;if (footprint && !observedFootprint(footprint)) return;diff --git a/test/cdp-managed-text-selection.mjs b/test/cdp-managed-text-selection.mjsnew file mode 100644index 000000000..a49ff6f91--- /dev/null+++ b/test/cdp-managed-text-selection.mjs@@ -0,0 +1,113 @@+import assert from 'node:assert/strict';+import { test } from 'node:test';+import { build } from 'esbuild';+import { chromium } from 'playwright';+import { cdpClient } from '../src/chrome/src/cdp/cdp-client.js';++// Real ProseMirror transactions and trusted Chromium input exercise the whole+// replacement path, including application model readback after native input.+const bundle = (await build({ stdin: { resolveDir: process.cwd(), contents: `+ import { Schema } from 'prosemirror-model';+ import { EditorState, TextSelection } from 'prosemirror-state';+ import { EditorView } from 'prosemirror-view';+ import { keymap } from 'prosemirror-keymap';+ import { baseKeymap } from 'prosemirror-commands';+ const schema = new Schema({ nodes: {+ doc: { content: 'block+' },+ paragraph: { group: 'block', content: 'inline*', toDOM: () => ['p', 0] },+ heading: { group: 'block', content: 'inline*', toDOM: () => ['h2', 0] },+ blockquote: { group: 'block', content: 'block+', toDOM: () => ['blockquote', 0] },+ bullet_list: { group: 'block', content: 'list_item+', toDOM: () => ['ul', 0] },+ list_item: { content: 'paragraph block*', toDOM: () => ['li', 0] },+ image: { inline: true, group: 'inline', atom: true, toDOM: () => ['img', { alt: 'Owned image', width: 20, height: 20 }] },+ hard_break: { inline: true, group: 'inline', selectable: false, toDOM: () => ['br'] },+ text: { group: 'inline' },+ } });+ window.qaMount = (json, partial = null) => {+ window.qaView?.destroy();+ document.querySelector('#host').replaceChildren();+ window.qaView = new EditorView(document.querySelector('#host'), {+ state: EditorState.create({ schema, doc: schema.nodeFromJSON(json), plugins: [keymap(baseKeymap)] }),+ dispatchTransaction(transaction) { this.updateState(this.state.apply(transaction)); },+ handleKeyDown(view, event) {+ if (!partial || event.code !== 'KeyA' || !(event.ctrlKey || event.metaKey)) return false;+ event.preventDefault();+ view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, partial.from, partial.to)));+ return true;+ },+ });+ window.qaEvents = [];+ qaView.dom.addEventListener('input', event => qaEvents.push({ trusted: event.isTrusted, inputType: event.inputType }));+ };+ window.qaSnapshot = () => ({ doc: qaView.state.doc.toJSON(), text: qaView.state.doc.textBetween(0, qaView.state.doc.content.size, '\\n'),+ html: qaView.dom.innerHTML, events: qaEvents });+` }, bundle: true, write: false, format: 'iife', platform: 'browser' })).outputFiles[0].text;+const paragraph = text => ({ type: 'paragraph', ...(text ? { content: [{ type: 'text', text }] } : {}) });+const text = 'Old owned draft';+const documentOf = (...content) => ({ type: 'doc', content });+const replacement = 'One complete replacement 🧠.';++test('Chrome: managed replacement selects complete structured ProseMirror documents', async t => {+ const browser = await chromium.launch({ headless: true });+ const original = { attach: cdpClient.attach, sendCommand: cdpClient.sendCommand };+ try {+ const page = await browser.newPage();+ const session = await page.context().newCDPSession(page);+ const commands = [], errors = [];+ page.on('pageerror', error => errors.push(error.message));+ await page.setContent('<style>.ProseMirror{min-height:100px;width:600px}p,h2{min-height:24px;margin:0}</style><div id="host"></div>');+ await page.addScriptTag({ content: bundle });+ cdpClient.attach = async () => {};+ cdpClient.sendCommand = async (_tab, method, params) => {+ commands.push({ method, params });+ return session.send(method, params);+ };+ for (const [name, doc] of [+ ['heading', documentOf({ type: 'heading', content: [{ type: 'text', text }] })],+ ['list', documentOf({ type: 'bullet_list', content: [{ type: 'list_item', content: [paragraph(text)] }] })],+ ['blockquote', documentOf({ type: 'blockquote', content: [paragraph(text)] })],+ ['mixed blocks', documentOf({ type: 'heading', content: [{ type: 'text', text }] }, { type: 'blockquote', content: [paragraph('Other paragraph')] })],+ ['empty trailing paragraph', documentOf(paragraph(text), paragraph(''))],+ ['empty leading paragraph', documentOf(paragraph(''), paragraph(text))],+ ['empty surrounding paragraphs', documentOf(paragraph(''), paragraph(text), paragraph(''))],+ ['only empty paragraphs', documentOf(paragraph(''), paragraph(''))],+ ['inline image', documentOf({ type: 'paragraph', content: [{ type: 'text', text }, { type: 'image' }] })],+ ['authored trailing break', documentOf({ type: 'paragraph', content: [{ type: 'text', text }, { type: 'hard_break' }] })],+ ]) await t.test(name, async () => {+ await page.evaluate(doc => qaMount(doc), doc); commands.length = 0;+ const result = await cdpClient.typeText(81, '.ProseMirror', replacement, true);+ const snapshot = await page.evaluate(() => qaSnapshot());+ assert.equal(result.success, true, JSON.stringify({ result, snapshot }));+ assert.equal(result.verified, true);+ assert.equal(snapshot.text, replacement, 'Compare the actual application document, including empty blocks.');+ assert.equal(commands.filter(command => command.method === 'Input.insertText').length, 1);+ assert.equal(commands.some(command => command.params?.code === 'Delete'), false);+ assert.ok(snapshot.events.every(event => event.trusted));+ assert.deepEqual(errors, []);+ });+ for (const [name, doc, partial] of [+ ['omitted trailing empty paragraph', documentOf(paragraph(text), paragraph('')), { from: 1, to: text.length + 1 }],+ ['omitted leading empty paragraph', documentOf(paragraph(''), paragraph(text)), { from: 3, to: text.length + 3 }],+ ['omitted inline image', documentOf({ type: 'paragraph', content: [{ type: 'text', text }, { type: 'image' }] }), { from: 1, to: text.length + 1 }],+ ['omitted authored hard break', documentOf({ type: 'paragraph', content: [{ type: 'text', text }, { type: 'hard_break' }] }), { from: 1, to: text.length + 1 }],+ ['omitted empty paragraph with collapsed selection', documentOf(paragraph(''), paragraph('')), { from: 1, to: 1 }],+ ]) await t.test(name, async () => {+ await page.evaluate(({ doc, partial }) => qaMount(doc, partial), { doc, partial }); commands.length = 0;+ const before = await page.evaluate(() => qaSnapshot());+ const result = await cdpClient.typeText(81, '.ProseMirror', replacement, true);+ const after = await page.evaluate(() => qaSnapshot());+ assert.equal(result.success, false, JSON.stringify({ result, after }));+ assert.equal(result.mutationMayHaveOccurred, false);+ assert.equal(result.outcomeUnknown, false); assert.equal(result.retryable, true);+ assert.deepEqual(after.doc, before.doc, 'A partial selection leaves the original application document intact.');+ assert.equal(after.html, before.html);+ assert.deepEqual(after.events, []);+ assert.equal(commands.some(command => command.method === 'Input.insertText' || command.params?.code === 'Delete'), false);+ assert.deepEqual(errors, []);+ });+ await session.detach();+ } finally {+ Object.assign(cdpClient, original);+ await browser.close();+ }+});diff --git a/test/page-monitor-dialog.mjs b/test/page-monitor-dialog.mjsindex da62912c3..861940d24 100644--- a/test/page-monitor-dialog.mjs+++ b/test/page-monitor-dialog.mjs@@ -97,7 +97,7 @@ for (const build of ['chrome', 'firefox']) {assert.equal((await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.postRef })).ready, true);const anonymous = await validate(page, snapshot, { tool: 'click_ax', ref_id: snapshot.anonymousRef });assert.equal(anonymous.ready, false);- assert.equal(anonymous.uncertified, true, 'An anonymous toolbar still lacks an entity boundary');+ assert.equal(anonymous.reason, 'target_uncovered', 'The background toolbar was not observed in the dialog capture');} finally { await context.close(); }});@@ -534,3 +534,55 @@ test('Chrome and Firefox dialog ownership logic stays byte-identical', () => {const source = build => fs.readFileSync(new URL(`../src/${build}/src/content/page-monitor.js`, import.meta.url), 'utf8');assert.equal(source('chrome'), source('firefox'));});++for (const [build, launcher] of [['chrome', chromium], ['firefox', firefox]]) {+ test(`${build}: large occluded background remains responsive without acquiring action authority`, async () => {+ const browser = await launcher.launch({ headless: true });+ const { context, page } = await fixture(browser, build);+ try {+ await page.evaluate(() => {+ const composer = document.getElementById('composer');+ Object.assign(composer.style, { zIndex: '10', background: 'white' });+ const background = document.createElement('div'); background.id = 'large-background';+ for (let group = 0; group < 100; group++) {+ const region = document.createElement('section'); region.setAttribute('role', 'region');+ region.style.cssText = 'position:absolute;left:40px;top:40px;width:100px;height:80px';+ const heading = document.createElement('h2'); heading.textContent = 'Owned background ' + group;+ region.append(heading);+ for (let index = 0; index < 20; index++) {+ const button = document.createElement('button'); button.id = `background-${group}-${index}`;+ button.style.cssText = 'position:absolute;left:0;top:0;width:100px;height:30px';+ const label = document.createElement('span'); label.textContent = 'Background action ' + index;+ button.append(label); region.append(button);+ }+ background.append(region);+ }+ document.body.append(background);+ });+ const measurement = await page.evaluate(async () => {+ const generate = window.__generateAccessibilityTree;+ let treeMs = 0;+ window.__generateAccessibilityTree = (...args) => {+ const start = performance.now();+ try { return generate(...args); }+ finally { treeMs += performance.now() - start; }+ };+ const start = performance.now();+ const snapshot = await deliver('page_monitor_capture_model', { includeTree: true });+ return { snapshot, elapsed: performance.now() - start, treeMs,+ editorRef: __wb_ax_ref(document.getElementById('editor')),+ backgroundRef: __wb_ax_ref(document.getElementById('background-0-0')) };+ });+ console.log(JSON.stringify({ build, captureMs: Math.round(measurement.elapsed), treeMs: Math.round(measurement.treeMs), backgroundControls: 2000 }));+ assert.equal(measurement.snapshot.ready, true);+ assert.ok(measurement.elapsed < 3000, `One model observation must remain responsive: ${measurement.elapsed}ms`);+ const validateTarget = ref_id => page.evaluate(({ snapshotToken, ref_id }) => deliver('page_monitor_validate_model', {+ snapshotToken, tool: 'click_ax', ref_id,+ }), { snapshotToken: measurement.snapshot.snapshotToken, ref_id });+ assert.equal((await validateTarget(measurement.editorRef)).ready, true);+ assert.equal((await validateTarget(measurement.backgroundRef)).ready, false, 'An unobserved background cannot borrow the composer certificate.');+ await page.locator('#audience').evaluate(node => { node.textContent = 'Different audience'; });+ assert.equal((await validateTarget(measurement.editorRef)).ready, false, 'Capture speed cannot weaken the complete local identity fence.');+ } finally { await context.close(); await browser.close(); }+ });+}diff --git a/test/quality/bluesky-composer-mv3.mjs b/test/quality/bluesky-composer-mv3.mjsindex c5ae1a5b7..423812b5f 100644--- a/test/quality/bluesky-composer-mv3.mjs+++ b/test/quality/bluesky-composer-mv3.mjs@@ -97,7 +97,8 @@ const server = http.createServer(async (request, response) => {await current.page.evaluate(() => qaChurnFeed());current.inferenceChanges++;await new Promise(resolve => setTimeout(resolve, 240));- call = { name: current.tool, args: { ref_id: current.beforeWrite.editor, text: body, clear: true } };+ call = { name: current.tool, args: { ...(current.tool === 'type_text'+ ? { selector: '.ProseMirror' } : { ref_id: current.beforeWrite.editor }), text: body, clear: true } };} else if (step === 2) {current.writeResult = tools.findLast(tool => tool.name === current.tool)?.result;current.afterWrite = await current.page.evaluate(() => qaSnapshot());@@ -112,6 +113,12 @@ const server = http.createServer(async (request, response) => {call = { name: 'click_ax', args: { ref_id: fresh.publish } };} else if (step === 4 && current.writeResult?.success === true)call = { name: 'get_accessibility_tree', args: { filter: 'all' } };+ else if (step > 3 && step % 2 === 1 && current.writeResult?.success === true+ && !tools.some(tool => tool.name === 'click_ax') && last?.name === 'get_accessibility_tree') {+ const fresh = references(observed?.result); assert.ok(fresh.publish);+ current.publishRetryReobserved = true;+ call = { name: 'click_ax', args: { ref_id: fresh.publish } };+ } else if (last?.name === 'click_ax') call = { name: 'get_accessibility_tree', args: { filter: 'all' } };else call = { name: 'done', args: { outcome: current.writeResult?.success === true ? 'success' : 'partial',summary: 'The exact owned local Bluesky post was published once and freshly verified.' } };current.calls.push(call);@@ -150,7 +157,7 @@ body{margin:0;font:16px sans-serif;background:#eee}#composer{position:absolute;l<div id="editor-row"><div data-testid="userAvatarImage" data-expoimage="true"><img id="avatar" alt="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='42' height='42'%3E%3Crect width='42' height='42' fill='%238ac'/%3E%3C/svg%3E"></div><div id="editor-host"></div></div><div id="footer"><div role="button" tabindex="0" aria-label="Anyone can interact" data-testid="openReplyGateButton">Anyone can interact</div><div role="button" tabindex="0" aria-label="Add image">Add image</div></div></div></div><script>-qaEditorLibrary.mountEditor('');window.qaEvents=[];window.qaCommands=[];window.qaFeedChanges=0;window.qaSaved=[];+qaEditorLibrary.mountEditor(window.qaInitialDraft||'');window.qaEvents=[];window.qaCommands=[];window.qaFeedChanges=0;window.qaSaved=[];for(const type of ['beforeinput','input','paste'])document.querySelector('#editor-host').addEventListener(type,event=>qaEvents.push({type,trusted:event.isTrusted,inputType:event.inputType,data:event.data}),true);const execCommand=document.execCommand.bind(document);@@ -228,15 +235,20 @@ try {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);- for(const {scenario,tool,body} of [+ for(const {scenario,tool,body,prefilled} of [{scenario:'set_field',tool:'set_field',body:singleLineBody},{scenario:'type_ax',tool:'type_ax',body:singleLineBody},{scenario:'set_field_multiline',tool:'set_field',body:multilineBody},- ]){- const page=await context.newPage(),pageErrors=[];page.on('pageerror',error=>pageErrors.push(error.message));await page.goto(fixtureUrl);+ {scenario:'prefilled_type_ax',tool:'type_ax',body:singleLineBody,prefilled:true},+ {scenario:'prefilled_type_text',tool:'type_text',body:singleLineBody,prefilled:true},+ ].filter(item=>!process.env.WEBBRAIN_QUALITY_BLUESKY_CASE||item.scenario===process.env.WEBBRAIN_QUALITY_BLUESKY_CASE)){+ const page=await context.newPage(),pageErrors=[];page.on('pageerror',error=>pageErrors.push(error.message));+ if(prefilled)await page.addInitScript(()=>{window.qaInitialDraft='Old owned draft "Local book" by @owned.bsky.social.';});+ await page.goto(fixtureUrl);await page.waitForSelector('.ProseMirror');const initial=await page.evaluate(()=>qaSnapshot());- assert.equal(initial.model,'');assert.equal(initial.editorName,null);assert.equal(initial.placeholder,"What's up?");assert.equal(initial.publishEnabled,false);+ assert.equal(initial.model,prefilled?'Old owned draft "Local book" by @owned.bsky.social.':'');assert.equal(initial.editorName,null);+ assert.equal(initial.placeholder,prefilled?null:"What's up?");assert.equal(initial.publishEnabled,!!prefilled);const tabId=await harness.evaluate(async url=>(await chrome.tabs.query({})).findLast(tab=>tab.url===url)?.id,fixtureUrl);assert.ok(tabId);current={scenario,tool,body,page,marker:`Owned Bluesky regression path ${scenario}.`,requests:[],calls:[],steps:0,compilers:0,audits:0,judges:0,inferenceChanges:0};const probeStart=await worker.evaluate(()=>({commands:blueskyFixtureProbe.commands.length,transports:blueskyFixtureProbe.transports.length}));diff --git a/test/quality/inline-social-composer-mv3.mjs b/test/quality/inline-social-composer-mv3.mjsindex 65fd2e039..2ee13b79d 100644--- a/test/quality/inline-social-composer-mv3.mjs+++ b/test/quality/inline-social-composer-mv3.mjs@@ -28,6 +28,11 @@ const body = 'One owned inline draft: exact spaces and Turkish ıİşŞğĞüÜconst cases = [{ name: 'set_field', tool: 'set_field' },{ name: 'type_ax', tool: 'type_ax' },+ { name: 'prefilled_set_field', tool: 'set_field', prefilled: true },+ { name: 'prefilled_type_ax', tool: 'type_ax', prefilled: true },+ { name: 'prefilled_type_text', tool: 'type_text', prefilled: true },+ { name: 'modal_prefilled_type_ax', tool: 'type_ax', prefilled: true, modal: true },+ { name: 'prefilled_selection_interrupted', tool: 'type_text', prefilled: true, partialSelection: true },{ name: 'focus_expansion', tool: 'set_field', focusExpansion: true },{ name: 'native_preparation_retry', tool: 'set_field', nativePreparationVeto: true },{ name: 'owner_changed', tool: 'set_field', change: 'owner' },@@ -126,7 +131,8 @@ const server = http.createServer(async (request, response) => {}, current.change || null);current.inferenceChanges++;await new Promise(resolve => setTimeout(resolve, 240));- call = { name: current.tool, args: { ref_id: current.beforeWrite.editor, text: body, clear: true } };+ call = { name: current.tool, args: { ...(current.tool === 'type_text'+ ? { selector: '[data-testid="tweetTextarea_0"]' } : { ref_id: current.beforeWrite.editor }), text: body, clear: true } };} else if (step === 2) {current.writeResult = tools.findLast(tool => tool.name === current.tool)?.result;current.afterWrite = await current.page.evaluate(() => qaSnapshot());@@ -172,6 +178,16 @@ const server = http.createServer(async (request, response) => {call = { name: 'click_ax', args: { ref_id: fresh.post } };} else if (step === 6 && current.nativePreparationVeto)call = { name: 'get_accessibility_tree', args: { filter: 'all' } };+ else if (!current.change && !current.nativePreparationVeto && current.writeResult?.success === true+ && step > (current.focusExpansion ? 5 : 3) && !tools.some(tool => tool.name === 'click_ax')+ && last?.name === 'get_accessibility_tree' && step % 2 === 1) {+ // A superseded decision sent no input. Observe again before emitting+ // another Post decision; never replay an actually dispatched click.+ const fresh = references(observed?.result);+ assert.ok(fresh.post); current.postRetryReobserved = true;+ call = { name: 'click_ax', args: { ref_id: fresh.post } };+ } else if (last?.name === 'click_ax' && !current.change)+ call = { name: 'get_accessibility_tree', args: { filter: 'all' } };else if (step === (current.focusExpansion ? 6 : 4) && !current.change && current.writeResult?.success === true)call = { name: 'get_accessibility_tree', args: { filter: 'all' } };else call = { name: 'done', args: { outcome: current.change || current.writeResult?.success !== true ? 'partial' : 'success',@@ -206,7 +222,9 @@ window.qaEvents=[];window.qaCommands=[];window.qaFeedChanges=0;window.qaSaved=[]window.qaExpandOnFocus=!!window.qaExpandOnFocus;const root=ReactDOM.createRoot(document.querySelector('#app'));function App(){- const [editorState,setEditorState]=React.useState(()=>Draft.EditorState.createEmpty());+ const [editorState,setEditorState]=React.useState(()=>window.qaInitialDraft+ ?Draft.EditorState.createWithContent(Draft.ContentState.createFromText(window.qaInitialDraft))+ :Draft.EditorState.createEmpty());const [identity,setIdentity]=React.useState('${account}');const [audience,setAudience]=React.useState(window.qaExpandOnFocus?null:'Everyone can reply');const [ownerVersion,setOwnerVersion]=React.useState(0);@@ -235,7 +253,7 @@ function App(){React.createElement('nav',{className:'tabs','aria-label':'Home timeline tabs'},React.createElement('button',{type:'button',role:'tab','aria-selected':'true'},'For you'),React.createElement('button',{type:'button',role:'tab','aria-selected':'false'},'Following')),- React.createElement('div',{id:'inline-owner',key:ownerVersion},+ React.createElement('div',{id:'inline-owner',key:ownerVersion,role:window.qaModal&&!saved?'dialog':undefined},React.createElement('a',{className:'avatar',href:'/'+identity,'aria-label':'Owned QA account avatar'},'QA'),React.createElement('div',{className:'compose-inner',onFocus:()=>{if(window.qaExpandOnFocus&&!audience)ReactDOM.flushSync(()=>setAudience('Everyone can reply'));}},React.createElement(Draft.Editor,{editorState,onChange,ariaLabel:'Post text',webDriverTestID:'tweetTextarea_0',placeholder:'What is happening?!'}),@@ -266,6 +284,9 @@ window.qaArmPreparationOverlay=()=>document.querySelector('#post').addEventListedocument.body.append(overlay);window.qaPreparationOverlays++;},{once:true});window.qaClearPreparationOverlay=()=>document.getElementById('qa-native-preparation-overlay')?.remove();+if(window.qaPartialSelection)document.querySelector('[data-testid="tweetTextarea_0"]').addEventListener('keydown',event=>{+ if(event.isTrusted&&event.code==='KeyA'&&(event.ctrlKey||event.metaKey))event.preventDefault();+},true);for(const type of ['beforeinput','input','paste'])document.querySelector('#app').addEventListener(type,event=>{if(event.target.closest('[data-testid="tweetTextarea_0"]'))qaEvents.push({type,trusted:event.isTrusted,inputType:event.inputType,data:type==='paste'?event.clipboardData?.getData('text/plain'):event.data});@@ -361,13 +382,17 @@ try {const page = await context.newPage(), pageErrors = [];page.on('pageerror', error => pageErrors.push(error.message));if (specification.focusExpansion) await page.addInitScript(() => { window.qaExpandOnFocus = true; });+ if (specification.prefilled) await page.addInitScript(() => { window.qaInitialDraft = 'Old owned draft "Local book" by @ownedqa.'; });+ if (specification.modal) await page.addInitScript(() => { window.qaModal = true; });+ if (specification.partialSelection) await page.addInitScript(() => { window.qaPartialSelection = true; });await page.goto(fixtureUrl);await page.waitForSelector('[data-testid="tweetTextarea_0"]');const initial = await page.evaluate(() => ({ state: qaSnapshot(), headings: document.querySelectorAll('h1,h2,h3,h4,h5,h6,[role="heading"]').length,formsOrDialogs: document.querySelectorAll('form,dialog,[role="form"],[role="dialog"]').length }));- assert.equal(initial.state.model, ''); assert.equal(initial.state.postEnabled, false);+ assert.equal(initial.state.model, specification.prefilled ? 'Old owned draft "Local book" by @ownedqa.' : '');+ assert.equal(initial.state.postEnabled, !!specification.prefilled);if (specification.focusExpansion) assert.equal(initial.state.audience, null);- assert.equal(initial.headings, 0); assert.equal(initial.formsOrDialogs, 0);+ assert.equal(initial.headings, 0); assert.equal(initial.formsOrDialogs, specification.modal ? 1 : 0);const tabId = await harness.evaluate(async url => (await chrome.tabs.query({})).findLast(tab => tab.url === url)?.id, fixtureUrl);assert.ok(tabId);current = { ...specification, page, tabId, marker: `Owned inline regression case ${specification.name}.`, requests: [], calls: [],@@ -418,6 +443,15 @@ Re-observe the Post button after writing, click it once, then verify the owned lassert.deepEqual(localPosts, []); assert.equal(clicks.length, 0);assert.equal(probe.commands.filter(command => command.method === 'Input.insertText').length, 0);assert.deepEqual(state.events, [], 'A stale owner must be rejected before page input.');+ } else if (specification.partialSelection) {+ assert.equal(writes.length, 1);+ assert.equal(writes[0].result.success, false); assert.equal(writes[0].result.mutationMayHaveOccurred, false);+ assert.equal(writes[0].result.outcomeUnknown, false); assert.equal(writes[0].result.retryable, true);+ assert.equal(state.model, initial.state.model, 'Failed selection preserves the complete original application draft.');+ assert.deepEqual(state.saved, []); assert.deepEqual(localPosts, []); assert.equal(clicks.length, 0);+ assert.equal(probe.commands.filter(command => command.method === 'Input.insertText').length, 0);+ assert.equal(probe.commands.some(command => command.params?.code === 'Delete'), false);+ assert.deepEqual(state.events, [], 'An unproved replacement selection never dispatches text input.');} else {assert.equal(writes.length, specification.focusExpansion ? 2 : 1, 'Only an explicit fresh decision may retry a positively undispatched write.');if (specification.focusExpansion) {diff --git a/test/social-publish-contract.mjs b/test/social-publish-contract.mjsindex 86f1def63..3c533bf34 100644--- a/test/social-publish-contract.mjs+++ b/test/social-publish-contract.mjs@@ -396,6 +396,66 @@ for (const browser of ['chrome', 'firefox']) {});}+ test(`${browser}: existing-draft confirmation displays exact quotes before binding a human answer`, async () => {+ for (const platform of ['twitter', 'bluesky']) {+ const body = 'Just finished "Local book" by @ownedqa. Keep literal \\n text.';+ const encoded = JSON.stringify(body).slice(1, -1);+ const raw = { version: 1, status: 'clarify', actions: [], requirements: null, prohibited: [], reason: 'Missing post content' };+ const f = setup(`Publish the existing draft on ${platform === 'twitter' ? 'X' : 'Bluesky'}`, raw);+ const pageUrl = platform === 'twitter' ? 'https://x.com/compose/post' : 'https://bsky.app/';+ f.agent._currentUrl = async () => pageUrl;+ f.detected.publicationSnapshot = snapshot(body, platform === 'twitter' ? 'twitter:alice' : 'bluesky:alice.bsky.social');+ const blocked = await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2001' }, f.detected, f.provider);+ assert.equal(blocked.noDispatch, true); assert.equal(f.guard.socialPublication.contract.status, 'clarify');+ f.agent._persistNow = async () => {}; f.agent.clarifyTimeoutSec = 0;+ let shown;+ const result = await f.agent.executeTool(f.tabId, 'clarify', {+ question: `Publish this draft: "${encoded}"?`, options: [`Publish: "${encoded}"`, 'Cancel'], safe_first: true,+ }, (type, data) => {+ if (type !== 'clarify') return;+ shown = data;+ assert.equal(data.question, `Publish this draft: "${body}"?`);+ assert.equal(data.options[0], `Publish: "${body}"`);+ assert.equal(data.requireExplicitAnswer, true, 'Page-derived draft text cannot become an automatic approval.');+ f.agent.submitClarifyResponse(f.tabId, data.clarifyId, data.options[0], 'option');+ });+ assert.equal(result.answer, shown.options[0]); assert.equal(result.source, 'option');+ assert.equal(f.guard.socialPublicationClarifications[0].question, shown.question);+ assert.equal(f.guard.socialPublicationClarifications[0].answer, shown.options[0]);+ f.agent._chatWithCostAllowance = async (_provider, messages, _options, _cost, meta) => {+ const input = JSON.parse(messages[1].content);+ assert.equal(input.sources.clarification_question0, shown.question);+ assert.equal(input.sources.clarification_answer0, shown.options[0]);+ if (meta.generationName === 'social_publication_authorization') return { content: JSON.stringify({ key: input.key, actionId: 'p1', authorized: true, reason: 'Exact human-confirmed draft.' }) };+ const action = rawAction('p1', platform, body);+ action.posts[0].body.source = ref(body, 'clarification_answer0');+ return { content: JSON.stringify(rawContract([action])) };+ };+ assert.equal(await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2001' }, f.detected, f.provider), null);+ assert.equal(f.guard.socialPublication.contract.actions[0].posts[0].body.value, body);+ assert.deepEqual(f.guard.socialPublication.outcomes, {}, 'Confirmation and preflight never dispatch a post.');+ }+ });++ test(`${browser}: escaped draft display repair cannot borrow a different draft, route, task or purpose`, async () => {+ const body = 'Owned "quoted" draft', encoded = JSON.stringify(body).slice(1, -1);+ for (const mutation of [+ f => { f.detected.publicationSnapshot.posts[0].bodyText = 'Other "quoted" draft'; },+ f => { f.detected.publicationSnapshot.complete = false; },+ f => { f.agent._currentUrl = async () => 'https://x.com/other'; },+ f => { f.guard.taskKey = 'superseded-task'; },+ (_f, args) => { args.purpose = 'research_escalation'; },+ ]) {+ const f = setup('Publish the existing draft', { version: 1, status: 'clarify', actions: [], requirements: null, prohibited: [], reason: 'Missing post content' });+ f.detected.publicationSnapshot = snapshot(body);+ await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'click_ax', { ref_id: 'ref_2001' }, f.detected, f.provider);+ const args = { question: `Publish "${encoded}"?`, options: [`Publish "${encoded}"`, 'Cancel'] };+ mutation(f, args);+ assert.equal(await f.agent._socialDraftClarificationArgs(f.tabId, args), args);+ assert.deepEqual(f.guard.socialPublication.outcomes, {});+ }+ });+test(`${browser}: a referenced four-post draft delivered through done reaches publication and audit intact`, async () => {const bodies = ['We released WebBrain.\n\nRead the article.', 'First: Jev.', 'Next: SafeSocial.', 'The takeaway.'];const draft = 'Option 1: Something else.\n\nOption 2:\n' + bodies.map((body, i) => `${i + 1}/4\n${body}`).join('\n\n');