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
Attach feedback traces to GitHub drafts with explicit consent
Barack Sokullu734f7c1e35ea
diff --git a/docs/privacy-and-data-flow.md b/docs/privacy-and-data-flow.mdindex 422fb70b6..4467f2d28 100644--- a/docs/privacy-and-data-flow.md+++ b/docs/privacy-and-data-flow.md@@ -268,6 +268,14 @@ the stored copies are not separately synced to WebBrain.### Trace Recorder+**Local feedback diagnostics** is enabled by default under Settings → Display.+When ordinary trace recording is off, it retains metadata-only diagnostics for+up to ten completed runs, seven days, and 2 MiB (with a 128 KiB per-run cap).+These automatic records never inherit lossless tracing and contain no raw+conversation/tool text or screenshot bytes. Turning the setting off stops this+recording and removes its automatic history; explicitly recorded traces remain.+Retention and event-budget omissions are identified in feedback exports.+When enabled (Settings → Display → "Record traces"), every agent run is writtento the local `webbrain_traces` IndexedDB database in one of two privacy tiers.An external/local provider with **Share queries for research** enabled also@@ -480,6 +488,19 @@ The only outbound HTTP requests are:7. **Encrypted Cloud Sync calls** to `https://api.webbrain.one/v1/sync` (only after a subscriber explicitly enables sync; vault content is encrypted before upload)8. **Slash-driven tab/screen recording** creates no outbound traffic (the .webm is saved to the Downloads folder via `chrome.downloads.download`)9. **Voluntary research shares** to `https://api.webbrain.one/v1/improvement/generations` and `/v1/improvement/diagnostic-traces` (only for a local or bring-your-own provider with its separate sharing switch enabled)+10. **Feedback trace attachments** uploaded by GitHub's native issue editor,+ only after the user chooses **Upload trace and open GitHub** in the extension.+ Preparing, viewing, and downloading the trace are local operations. The+ confirmation identifies the conversation, recorded content tier, run and+ screenshot counts, size, and any fallback or omissions. GitHub makes the+ attachment publicly accessible immediately, before the issue is submitted.+ **Continue without trace** uploads no trace. Export scrubs credential-shaped+ values, but conversation/page text and screenshots can still be sensitive.+ Temporary exports expire after one hour and are removed after completion,+ cancellation, or closing the destination tab. Failed handoffs can retry the+ same authorized bytes. Full traces that exceed the attachment limit use an+ explicitly disclosed diagnostic fallback; the original stays available as+ a local download.The `webRequest` API shortcut observer is on by default and does notcreate outbound requests; it observes replay metadata for requests@@ -718,6 +739,7 @@ CDP capture → JPEG/PNG data URL| Provider prompt/tool tier | Choose Compact, Mid, or Full tool exposure for non-cloud providers || Ask / Act / Dev mode | Choose read-only, normal action, or developer/page-inspection mode || Tracing toggle | Controls ordinary local trace recording; a separately opted-in provider research share records a run for metadata-only diagnostic upload even when this toggle is off |+| Local feedback diagnostics | Keeps bounded metadata locally when ordinary tracing is off; disabling it clears automatic history. Uploading a feedback attachment requires separate confirmation. || Screenshot fallback | Controls whether page images are sent to the LLM || Auto-screenshot mode | Controls how frequently viewport captures are sent || Strict secret handling | Keeps credentials out of assistant text and completion summaries: an instruction to the model, plus exact-match redaction in cloud runs of anything it typed, sent, or read from a labelled field |diff --git a/docs/security-model.md b/docs/security-model.mdindex 52d8869e5..82c2de489 100644--- a/docs/security-model.md+++ b/docs/security-model.md@@ -207,10 +207,28 @@ persistent setting, which remains active until the user turns it off.## Trace Data Isolation+The separately configurable **Local feedback diagnostics** setting is enabled+by default. When ordinary recording is disabled, it keeps only metadata locally,+bounded to ten completed runs, seven days, 2 MiB total, and 128 KiB per run.+It cannot enable lossless recording. Disabling it clears automatic records and+leaves explicit recordings intact.++Feedback prepares a snapshot of the conversation selected when the rating prompt+opened. A dedicated dialog must authorize the actual attachment before it leaves+the browser: GitHub uploads files immediately, even before issue submission.+Viewing a trace and continuing without it never authorize an upload. The handoff+is restricted to the chat panel, an exact GitHub repository and destination tab,+the top frame, an expiring random token, and immutable staged bytes. Transfers+are chunked; reloads do not automatically repeat an uncertain upload. The user+reviews and submits the GitHub issue separately. Legacy and lossless feedback+exports mask credential-shaped data, but this does not anonymize screenshots or+arbitrary conversation/page content.+The trace recorder (`trace/recorder.js`) writes to IndexedDB on the user's-machine when explicitly enabled (Settings → Display → "Record traces") or-when a local/bring-your-own provider's separate **Share queries for research**-switch is enabled for that run. The latter forces a local record so a bounded,+machine for bounded automatic feedback diagnostics, when explicitly enabled+(Settings → Display → "Record traces"), or when a local/bring-your-own provider's+separate **Share queries for research** switch is enabled for that run. The latter+forces a local record so a bounded,content-free diagnostic timeline can be uploaded under that explicit consent.The default tier is metadata-only: run records omit user and final assistanttext; event records keep allowlisted counts, timings, usage, status/error codes,diff --git a/package.json b/package.jsonindex 1a3fa32ff..693360100 100644--- a/package.json+++ b/package.json@@ -5,7 +5,7 @@"private": true,"type": "module","scripts": {- "test": "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-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs && npm run test:firefox-bidi && npm run test:runtime-lifecycle && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:openrouter-capabilities && 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 && node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security",+ "test": "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-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:runtime-lifecycle && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:openrouter-capabilities && 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 && node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security","test:captcha:ui": "node test/captcha-settings-ui.mjs && node test/captcha-application-ui.mjs","test:captcha:bridge:ui": "node test/captcha-callback-bridge-ui.mjs","test:billing-notice": "node test/billing-payment-notice.mjs",@@ -71,7 +71,8 @@"test:compass-quota:ui": "node test/compass-quota-ui.mjs","test:generative-media": "node --test test/generative-media.mjs test/generative-media-availability.mjs","test:generative-media:ui": "node test/generative-media-ui.mjs",- "test:generative-media:extension": "node test/generative-media-extension.mjs"+ "test:generative-media:extension": "node test/generative-media-extension.mjs",+ "test:feedback": "node --test test/feedback-traces.mjs"},"devDependencies": {"playwright": "^1.48.0",diff --git a/src/chrome/src/agent/trace-export.js b/src/chrome/src/agent/trace-export.jsindex 95b945457..4190dd192 100644--- a/src/chrome/src/agent/trace-export.js+++ b/src/chrome/src/agent/trace-export.js@@ -20,6 +20,7 @@*/import { isKnownKind } from '../trace/event-model.js';+import { isErrorCode } from '../trace/error-codes.js';import { isSensitiveCloudKey } from '../cloud-runs.js';const ARGS_LIMIT = 300;@@ -55,15 +56,40 @@ function redactExportValue(value, key = '') {return Object.fromEntries(Object.entries(value).map(([childKey, item]) => [childKey, redactExportValue(item, childKey)]));}-export function sanitizeTraceExport(payload) {- if (payload?.run?.lossless === true) return redactExportValue(payload);+const DIAGNOSTIC_CODE_KINDS = new Set(['error', 'turn_start', 'turn_end', 'step_start', 'step_end']);++function restoreDiagnosticCodes(entry, redacted) {+ if (!Array.isArray(entry?.events) || !Array.isArray(redacted?.events)) return;+ entry.events.forEach((event, index) => {+ const data = redacted.events[index]?.data;+ if (!data || typeof data !== 'object') return;+ // Only catalog codes in recorder metadata are public diagnostics. A code+ // in tool arguments/results or conversation content remains a credential.+ if (DIAGNOSTIC_CODE_KINDS.has(event.kind) && isErrorCode(event.data?.code)) data.code = event.data.code;+ if (event.kind === 'note' && data.extra && isErrorCode(event.data?.extra?.code)) data.extra.code = event.data.extra.code;+ });+}++function redactTraceExport(payload) {+ const redacted = redactExportValue(payload);+ restoreDiagnosticCodes(payload, redacted);+ if (Array.isArray(payload?.runs) && Array.isArray(redacted?.runs)) {+ payload.runs.forEach((entry, index) => restoreDiagnosticCodes(entry, redacted.runs[index]));+ }+ return redacted;+}++export function sanitizeTraceExport(payload, { allRuns = false } = {}) {+ // Feedback can include legacy rows that predate the lossless marker.+ if (allRuns) return redactTraceExport(payload);+ if (payload?.run?.lossless === true) return redactTraceExport(payload);if (!Array.isArray(payload?.runs)) return payload;let changed = false;const runs = payload.runs.map((entry) => {if (entry?.run?.lossless !== true) return entry;changed = true;- return redactExportValue(entry);+ return redactTraceExport(entry);});return changed ? { ...payload, runs } : payload;diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 25bdd9a47..40510a21c 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -1,6 +1,8 @@import { resolveDecisionConfig, listDecisionModels } from './agent/decision-config.js';import { probeDecisionVision } from './agent/decision-vision-probe.js';import { installSafeSocialBackground } from './safesocial/background.js';+import { createFeedbackHandoff } from './feedback-handoff.js';+const feedbackHandoff = createFeedbackHandoff(chrome);import { ProviderManager } from './providers/manager.js';import {WEBGPU_COMPASS_TINY_V2_MODEL_ID,@@ -2837,6 +2839,7 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {});async function handleMessage(msg, sender) {+ if (String(msg.action || '').startsWith('feedback_')) return feedbackHandoff.handle(msg, sender);if (msg.action === 'chat_steer') {// Content scripts must never turn page text into a trusted human correction.if (sender?.url?.split(/[?#]/)[0] !== chrome.runtime.getURL('src/ui/sidepanel.html')) {diff --git a/src/chrome/src/config-transfer.js b/src/chrome/src/config-transfer.jsindex 7437499e5..d621f2731 100644--- a/src/chrome/src/config-transfer.js+++ b/src/chrome/src/config-transfer.js@@ -54,6 +54,7 @@ export const DEFAULT_CONFIG_SETTINGS = Object.freeze({completionConfetti: true,completionFlashTab: true,tracingEnabled: false,+ feedbackDiagnosticsEnabled: true,strictSecretMode: false,agentAllowLocalNetwork: false,scheduledTasksEnabled: true,@@ -136,6 +137,7 @@ const BOOLEAN_KEYS = new Set(['completionConfetti','completionFlashTab','tracingEnabled',+ 'feedbackDiagnosticsEnabled','strictSecretMode','agentAllowLocalNetwork','scheduledTasksEnabled',diff --git a/src/chrome/src/content/feedback-attachment.js b/src/chrome/src/content/feedback-attachment.jsnew file mode 100644index 000000000..ed6c42fde--- /dev/null+++ b/src/chrome/src/content/feedback-attachment.js@@ -0,0 +1,137 @@+(() => {+ if (globalThis.__webbrainFeedbackAttachment) return;+ globalThis.__webbrainFeedbackAttachment = true;+ const api = typeof browser !== 'undefined' ? browser : chrome;+ const destination = () => location.origin === 'https://github.com'+ && location.pathname === '/webbrain-one/webbrain/issues/new';+ if (!destination()) return;+ let draft, busy = false, banner, message, retryButton, downloadButton;+ const send = async (action, extra = {}) => {+ const result = await api.runtime.sendMessage({ target: 'background', action, id: draft?.id, token: draft?.token, ...extra });+ if (!result?.ok) throw new Error(result?.error || 'Feedback handoff failed.');+ return result;+ };+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));+ function editor() {+ const scope = document.querySelector('main') || document.body;+ return scope.querySelector('textarea[name="issue[body]"], textarea#issue_body')+ || [...scope.querySelectorAll('textarea')].find(input => !input.disabled && !input.readOnly);+ }+ function fileInput(input) {+ if (!input) return null;+ for (const scope of [input.closest('file-attachment'), input.closest('form'), document.querySelector('main')]) {+ if (!scope) continue;+ const candidates = [...scope.querySelectorAll('input[type="file"]')].filter(field => !field.disabled);+ if (candidates.length === 1) return candidates[0];+ }+ return null;+ }+ function attached(input) {+ // An arbitrary link or the filename by itself is not upload evidence.+ return [...String(input?.value || '').matchAll(/\[([^\]]+)\]\((https:\/\/[^\s)]+)\)/g)].some(match => {+ try {+ const url = new URL(match[2]);+ return match[1] === draft.filename && url.origin === 'https://github.com'+ && (url.pathname.startsWith('/user-attachments/files/') || url.pathname.startsWith('/files/'));+ } catch { return false; }+ });+ }+ function show(text, failed = false) {+ message.textContent = text;+ retryButton.hidden = !failed || !draft.includeTrace;+ downloadButton.hidden = !failed || !draft.includeTrace;+ }+ function createBanner() {+ banner = document.createElement('aside');+ banner.setAttribute('role', 'status');+ banner.style.cssText = 'position:fixed;bottom:20px;right:20px;z-index:2147483647;max-width:420px;padding:16px;border:1px solid #8b949e;border-radius:8px;background:#fff;color:#24292f;box-shadow:0 4px 24px #0003;font:14px/1.5 system-ui';+ message = document.createElement('p'); message.style.margin = '0 0 8px';+ retryButton = document.createElement('button'); retryButton.type = 'button';+ retryButton.textContent = draft.copy.retry || 'Retry attachment'; retryButton.hidden = true;+ retryButton.addEventListener('click', async () => {+ if (busy) return;+ retryButton.disabled = true;+ try { await send('feedback_retry'); await upload(); }+ catch (error) { show(error.message, true); }+ finally { retryButton.disabled = false; }+ });+ downloadButton = document.createElement('button'); downloadButton.type = 'button';+ downloadButton.textContent = draft.copy.download || 'Download trace'; downloadButton.hidden = true;+ downloadButton.addEventListener('click', () => void send('feedback_preview').catch(error => show(error.message, true)));+ const close = document.createElement('button'); close.type = 'button'; close.textContent = '×';+ close.setAttribute('aria-label', draft.copy.close || 'Close');+ close.style.cssText = 'float:right;margin-left:8px'; close.addEventListener('click', () => banner.remove());+ banner.append(close, message, retryButton, downloadButton); document.body.append(banner);+ }+ async function waitForEditor() {+ for (let attempt = 0; attempt < 120 && destination(); attempt++) {+ const input = editor();+ if (input) return input;+ await sleep(250);+ }+ throw new Error(draft.copy.failed || 'The GitHub editor is not available.');+ }+ async function complete() {+ await send('feedback_result', { success: true });+ show(draft.copy.ready || 'Trace attached. Review and submit your feedback on GitHub.');+ }+ async function upload() {+ if (busy || !destination()) return;+ busy = true;+ try {+ const input = await waitForEditor();+ if (attached(input)) { await complete(); return; }+ show(draft.copy.uploading || 'Attaching your trace. Please wait before submitting the issue.');+ const chunks = [];+ for (let offset = 0; offset < draft.size; offset += draft.chunkBytes) {+ if (!destination()) throw new Error('The feedback destination changed.');+ const response = await send('feedback_chunk', { offset });+ const binary = atob(response.base64);+ chunks.push(Uint8Array.from(binary, character => character.charCodeAt(0)));+ }+ let target;+ for (let attempt = 0; attempt < 80 && destination(); attempt++) {+ target = fileInput(editor());+ if (target) break;+ await sleep(250);+ }+ if (!target || !destination()) throw new Error(draft.copy.failed || 'The GitHub upload control is not available.');+ await send('feedback_upload_started');+ const transfer = new DataTransfer();+ transfer.items.add(new File(chunks, draft.filename, { type: draft.mimeType || 'application/json' }));+ target.files = transfer.files;+ target.dispatchEvent(new Event('input', { bubbles: true }));+ target.dispatchEvent(new Event('change', { bubbles: true }));+ for (let attempt = 0; attempt < 240 && destination(); attempt++) {+ if (attached(editor())) { await complete(); return; }+ await sleep(250);+ }+ throw new Error(draft.copy.failed || 'The trace attachment could not be confirmed.');+ } catch (error) {+ await send('feedback_result', { success: false }).catch(() => {});+ show(draft.copy.failed || error.message, true);+ } finally { busy = false; }+ }+ void (async () => {+ draft = await send('feedback_claim');+ draft.copy ||= {};+ createBanner();+ const input = await waitForEditor();+ // React listens to native input events. Never replace text the user edited.+ if (!input.value || input.value.trim() === draft.initialBody.trim()) {+ const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set;+ setter.call(input, draft.body);+ input.dispatchEvent(new Event('input', { bubbles: true }));+ input.dispatchEvent(new Event('change', { bubbles: true }));+ }+ if (!draft.includeTrace) {+ await send('feedback_result', { success: true });+ show(draft.copy.draftReady || 'Review and submit your feedback on GitHub.');+ } else if (attached(input)) await complete();+ else if (draft.status === 'uploading' || draft.status === 'failed') show(draft.copy.failed || 'Check the draft, then retry the attachment if needed.', true);+ else await upload();+ })().catch(error => {+ if (banner) show(draft?.copy?.failed || error.message, true);+ else globalThis.__webbrainFeedbackAttachment = false;+ });+})();diff --git a/src/chrome/src/feedback-handoff.js b/src/chrome/src/feedback-handoff.jsnew file mode 100644index 000000000..ad6b55bf5--- /dev/null+++ b/src/chrome/src/feedback-handoff.js@@ -0,0 +1,163 @@+import {+ getFeedbackDraft, listFeedbackDrafts, putFeedbackDraft, updateFeedbackDraft, deleteFeedbackDraft,+ sweepFeedbackDrafts, FEEDBACK_TTL_MS, FEEDBACK_CHUNK_BYTES,+} from './feedback-store.js';+import { buildFeedbackBody, FEEDBACK_ISSUES_URL } from './ui/store-review-prompt.js';+import { flushPendingWrites, pruneFeedbackDiagnostics } from './trace/recorder.js';++export function isFeedbackDestination(url) {+ try {+ const parsed = new URL(url);+ return parsed.origin === 'https://github.com'+ && parsed.pathname === '/webbrain-one/webbrain/issues/new';+ } catch { return false; }+}++export function mayReadFeedbackDraft(draft, sender, tabUrl, now = Date.now()) {+ return Boolean(draft && draft.authorized && draft.expiresAt > now+ && sender?.frameId === 0 && sender.tab?.id === draft.destinationTabId+ && isFeedbackDestination(sender.url) && isFeedbackDestination(tabUrl));+}++export function createFeedbackHandoff(api) {+ const inflight = new Set();+ const panelUrl = api.runtime.getURL('src/ui/sidepanel.html');+ const settingsUrl = api.runtime.getURL('src/ui/settings.html');+ const isPanel = sender => sender?.id === api.runtime.id+ && sender.url?.split(/[?#]/)[0] === panelUrl;+ async function cleanup() {+ const settings = await api.storage.local.get('feedbackDiagnosticsEnabled');+ await Promise.all([+ sweepFeedbackDrafts(),+ pruneFeedbackDiagnostics({ clear: settings.feedbackDiagnosticsEnabled === false }),+ ]);+ }+ const storeReady = cleanup().catch(() => {});++ async function inject(tabId) {+ await storeReady;+ if (inflight.has(tabId)) return;+ const tab = await api.tabs.get(tabId);+ if (!isFeedbackDestination(tab.url)) return;+ const draft = (await listFeedbackDrafts()).find(row => row.destinationTabId === tabId && row.authorized && row.expiresAt > Date.now());+ if (!draft) return;+ inflight.add(tabId);+ try {+ if (api.scripting?.executeScript) await api.scripting.executeScript({+ target: { tabId, frameIds: [0] }, files: ['src/content/feedback-attachment.js'],+ });+ else await api.tabs.executeScript(tabId, { file: 'src/content/feedback-attachment.js', frameId: 0 });+ } finally { inflight.delete(tabId); }+ }++ api.tabs.onUpdated.addListener((tabId, change) => {+ if (change.status === 'complete') void inject(tabId).catch(() => {});+ });+ api.tabs.onRemoved.addListener(tabId => { void sweepFeedbackDrafts({ tabId }).catch(() => {}); });+ api.alarms.onAlarm.addListener(alarm => {+ if (alarm.name === 'feedback-draft-cleanup') void cleanup().catch(() => {});+ });+ api.storage.onChanged?.addListener((changes, area) => {+ if (area === 'local' && changes.feedbackDiagnosticsEnabled?.newValue === false) {+ void pruneFeedbackDiagnostics({ clear: true }).catch(() => {});+ }+ });+ api.alarms.create('feedback-draft-cleanup', { periodInMinutes: 5 });+ // A worker may have restarted after the document loaded, without an update event.+ void storeReady.then(async () => {+ for (const draft of await listFeedbackDrafts()) {+ if (draft.destinationTabId !== null) void inject(draft.destinationTabId).catch(() => {});+ }+ }).catch(() => {});++ return {+ async handle(msg, sender) {+ await storeReady;+ if (msg.action === 'feedback_flush') {+ if (!isPanel(sender)) throw new Error('Chat panel only.');+ await flushPendingWrites();+ return { ok: true };+ }+ if (msg.action === 'feedback_clear_diagnostics') {+ if (sender?.id !== api.runtime.id || sender.url?.split(/[?#]/)[0] !== settingsUrl) throw new Error('Settings only.');+ await pruneFeedbackDiagnostics({ clear: true });+ return { ok: true };+ }+ if (msg.action === 'feedback_open') {+ if (!isPanel(sender)) throw new Error('Feedback can only be sent from the chat panel.');+ const rating = Math.max(1, Math.min(5, Math.round(Number(msg.rating) || 3)));+ const body = buildFeedbackBody({ rating, comment: msg.comment, traceNote: msg.traceNote });+ let draft = msg.includeTrace ? await getFeedbackDraft(String(msg.id || '')) : null;+ if (msg.includeTrace && (!draft?.blob || draft.expiresAt <= Date.now()+ || draft.status !== 'prepared')) throw new Error('Prepare and review the trace again before uploading.');+ // The dedicated action from the consent button authorizes these staged,+ // immutable bytes; page content cannot call this extension-page route.+ draft = draft || {+ id: crypto.randomUUID(), token: crypto.randomUUID(),+ createdAt: Date.now(), expiresAt: Date.now() + FEEDBACK_TTL_MS,+ };+ draft = { ...draft, body, initialBody: `**Rating:** ${rating}/5`,+ authorized: true, consentAt: msg.includeTrace ? Date.now() : null,+ status: 'pending', copy: msg.copy || {}, includeTrace: msg.includeTrace === true };+ if (encodeURIComponent(body).length < 6000) draft.initialBody = body;+ let tab;+ try {+ tab = await api.tabs.create({ url: 'about:blank' });+ draft.destinationTabId = tab.id;+ await putFeedbackDraft(draft);+ const url = new URL(FEEDBACK_ISSUES_URL);+ url.searchParams.set('title', `WebBrain feedback (${rating}/5)`);+ url.searchParams.set('body', draft.initialBody);+ await api.tabs.update(tab.id, { url: url.href });+ return { ok: true, tabId: tab.id };+ } catch (error) {+ await deleteFeedbackDraft(draft.id);+ if (tab) await api.tabs.remove(tab.id).catch(() => {});+ throw error;+ }+ }+ const draft = msg.action === 'feedback_claim'+ ? (await listFeedbackDrafts()).find(row => row.destinationTabId === sender?.tab?.id)+ : await getFeedbackDraft(String(msg.id || ''));+ const tab = sender?.tab ? await api.tabs.get(sender.tab.id) : null;+ if (sender?.id !== api.runtime.id || !mayReadFeedbackDraft(draft, sender, tab?.url)+ || (msg.action !== 'feedback_claim' && msg.token !== draft.token)) throw new Error('Unauthorized feedback handoff.');+ if (msg.action === 'feedback_claim') return {+ ok: true, id: draft.id, token: draft.token, body: draft.body, initialBody: draft.initialBody,+ filename: draft.filename, size: draft.blob?.size || 0, mimeType: draft.blob?.type,+ status: draft.status, includeTrace: draft.includeTrace, chunkBytes: FEEDBACK_CHUNK_BYTES,+ copy: draft.copy || {},+ };+ if (msg.action === 'feedback_preview') {+ if (!draft.includeTrace) throw new Error('No trace was selected.');+ await api.tabs.create({ url: api.runtime.getURL(`src/ui/feedback-trace-preview.html?id=${encodeURIComponent(draft.id)}`) });+ return { ok: true };+ }+ if (msg.action === 'feedback_chunk') {+ if (!draft.includeTrace || !Number.isSafeInteger(msg.offset) || msg.offset < 0 || msg.offset >= draft.blob.size) throw new Error('Invalid feedback chunk.');+ const bytes = new Uint8Array(await draft.blob.slice(msg.offset, msg.offset + FEEDBACK_CHUNK_BYTES).arrayBuffer());+ let binary = '';+ for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));+ return { ok: true, base64: btoa(binary) };+ }+ if (msg.action === 'feedback_upload_started') {+ await updateFeedbackDraft(draft.id, current => {+ if (!current?.includeTrace || !['pending', 'failed'].includes(current.status)) throw new Error('Attachment already dispatched.');+ return { ...current, status: 'uploading' };+ });+ return { ok: true };+ }+ if (msg.action === 'feedback_retry') {+ if (!draft.includeTrace || !['failed', 'uploading'].includes(draft.status)) throw new Error('No failed attachment to retry.');+ await putFeedbackDraft({ ...draft, status: 'failed' });+ return { ok: true };+ }+ if (msg.action === 'feedback_result') {+ if (msg.success === true) await deleteFeedbackDraft(draft.id);+ else await putFeedbackDraft({ ...draft, status: 'failed' });+ return { ok: true };+ }+ throw new Error('Unknown feedback action.');+ },+ };+}diff --git a/src/chrome/src/feedback-store.js b/src/chrome/src/feedback-store.jsnew file mode 100644index 000000000..e3762e5c9--- /dev/null+++ b/src/chrome/src/feedback-store.js@@ -0,0 +1,65 @@+export const FEEDBACK_TTL_MS = 60 * 60 * 1000;+export const FEEDBACK_CHUNK_BYTES = 128 * 1024;+let database;++function openDB() {+ if (!database) database = new Promise((resolve, reject) => {+ const request = indexedDB.open('webbrain_feedback', 1);+ request.onupgradeneeded = () => request.result.createObjectStore('drafts', { keyPath: 'id' });+ request.onsuccess = () => resolve(request.result);+ request.onerror = () => { database = null; reject(request.error); };+ });+ return database;+}++async function operation(mode, action) {+ const db = await openDB();+ return new Promise((resolve, reject) => {+ const transaction = db.transaction('drafts', mode);+ const request = action(transaction.objectStore('drafts'));+ transaction.oncomplete = () => resolve(request?.result);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback storage aborted.'));+ });+}++export const getFeedbackDraft = id => operation('readonly', store => store.get(id));+export const listFeedbackDrafts = () => operation('readonly', store => store.getAll());+export const putFeedbackDraft = draft => operation('readwrite', store => store.put(draft));+export const deleteFeedbackDraft = id => operation('readwrite', store => store.delete(id));++// A single transaction prevents two restarted/injected helpers from both+// dispatching the same attachment after reading a pending state.+export async function updateFeedbackDraft(id, update) {+ const db = await openDB();+ return new Promise((resolve, reject) => {+ const transaction = db.transaction('drafts', 'readwrite');+ const store = transaction.objectStore('drafts');+ const request = store.get(id);+ let updated;+ request.onsuccess = () => {+ try { updated = update(request.result); if (updated) store.put(updated); }+ catch (error) { reject(error); transaction.abort(); }+ };+ transaction.oncomplete = () => resolve(updated);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback update aborted.'));+ });+}++export async function stageFeedbackTrace(prepared) {+ const draft = {+ ...prepared, preview: undefined,+ id: crypto.randomUUID(), token: crypto.randomUUID(),+ createdAt: Date.now(), expiresAt: Date.now() + FEEDBACK_TTL_MS,+ authorized: false, status: 'prepared', destinationTabId: null,+ };+ await putFeedbackDraft(draft);+ return draft;+}++export async function sweepFeedbackDrafts({ now = Date.now(), tabId = null } = {}) {+ for (const draft of await listFeedbackDrafts()) {+ if (draft.expiresAt <= now || (tabId !== null && draft.destinationTabId === tabId)) await deleteFeedbackDraft(draft.id);+ }+}diff --git a/src/chrome/src/trace/feedback-export.js b/src/chrome/src/trace/feedback-export.jsnew file mode 100644index 000000000..b5e2ada1a--- /dev/null+++ b/src/chrome/src/trace/feedback-export.js@@ -0,0 +1,103 @@+import { exportRecordedSession } from './session-export.js';+import { sanitizeTraceExport } from '../agent/trace-export.js';+import { projectTraceEventData } from './privacy.js';+import { normalizeRuntimeTraceConfig } from './runtime-config.js';++export const FEEDBACK_ATTACHMENT_LIMIT = 20 * 1024 * 1024;++const DIAGNOSTIC_RUN_FIELDS = [+ 'runId', 'conversationId', 'parentRunId', 'parentSessionId', 'delegationDepth',+ 'startedAt', 'endedAt', 'durationMs', 'status', 'model', 'providerId', 'providerClass',+ 'webbrainVersion', 'traceFormatVersion', 'mode', 'stepCount', 'totalInputTokens',+ 'totalOutputTokens', 'totalCost', 'llmRequestCount', 'llmResponseCount', 'toolCallCount',+ 'visionSubCallCount', 'errorCount', 'retryCount', 'totalLlmLatencyMs', 'totalToolLatencyMs',+ 'feedbackOnly', 'feedbackHistoryOmitted', 'feedbackEventsOmitted',+];++export function diagnosticFeedbackPayload(payload) {+ return {+ ...payload,+ runs: payload.runs.map(({ run, events }) => ({+ // Legacy rows can have unknown content fields. A diagnostic fallback+ // must not copy those fields, including unknown event-envelope fields.+ run: { ...Object.fromEntries(DIAGNOSTIC_RUN_FIELDS.filter(key => run[key] !== undefined).map(key => [key, run[key]])),+ runtimeConfig: normalizeRuntimeTraceConfig(run.runtimeConfig), lossless: false },+ events: events.map(event => ({ runId: event.runId, seq: event.seq, ts: event.ts, kind: event.kind, data: {+ ...projectTraceEventData(event.kind, event.data),+ ...(event.kind === 'tool' && !event.data?.result ? {+ resultStatus: event.data?.resultStatus || 'unknown',+ ...(event.data?.resultErrorCode || event.data?.errorCode ? { resultErrorCode: event.data.resultErrorCode || event.data.errorCode } : {}),+ } : {}),+ } })),+ })),+ feedbackOmissions: [...(payload.feedbackOmissions || []), 'Full trace exceeds the attachment size limit; diagnostic metadata only.'],+ };+}++export async function prepareFeedbackTrace(store, sessionId, version = '', {+ limit = FEEDBACK_ATTACHMENT_LIMIT,+ compress = async blob => typeof CompressionStream === 'function'+ ? new Response(blob.stream().pipeThrough(new CompressionStream('gzip'))).blob() : null,+} = {}) {+ if (!sessionId) return null;+ const exported = await exportRecordedSession(store, sessionId, version);+ if (!exported.turnCount) return null;+ let payload = sanitizeTraceExport(JSON.parse(exported.json), { allRuns: true });+ const omissions = [];+ if (exported.recordingTruncated) omissions.push('Some content was omitted at recording time.');+ if (payload.runs.some(entry => entry.run.feedbackHistoryOmitted || entry.run.feedbackEventsOmitted)) {+ omissions.push('Automatic diagnostic history is bounded; older runs or events may be absent.');+ }+ payload.feedbackOmissions = omissions;+ const originalBlob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ let blob = originalBlob;+ let filename = `webbrain-feedback-${Date.now()}.json`;+ if (blob.size >= limit) {+ let compressed;+ try { compressed = await compress(blob); } catch { /* diagnostic fallback below */ }+ if (compressed && compressed.size < limit) {+ blob = new Blob([compressed], { type: 'application/gzip' });+ filename += '.gz';+ } else {+ payload = diagnosticFeedbackPayload(payload);+ // Bound the fallback as well; retain a visible omission marker.+ const budget = Math.min(limit / 2, 256 * 1024);+ let used = 0;+ payload.runs = payload.runs.slice().reverse().map(entry => {+ const events = [];+ for (const event of entry.events.slice().reverse()) {+ const size = new TextEncoder().encode(JSON.stringify(event)).length;+ if (used + size > budget) { entry.run.feedbackEventsOmitted = true; continue; }+ used += size;+ events.unshift(event);+ }+ return { run: entry.run, events };+ }).reverse();+ blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ // Whitespace and run headers also count toward GitHub's file limit.+ while (blob.size >= limit) {+ const entry = payload.runs.find(item => item.events.length);+ if (entry) { entry.events.shift(); entry.run.feedbackEventsOmitted = true; }+ else if (payload.runs.length > 1) {+ payload.runs.shift();+ if (!payload.feedbackOmissions.includes('Older runs omitted to fit the attachment.')) payload.feedbackOmissions.push('Older runs omitted to fit the attachment.');+ } else break;+ blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ }+ filename = filename.replace(/\.json$/, '-diagnostics.json');+ if (blob.size >= limit) throw new Error('Diagnostic attachment exceeds the size limit.');+ }+ }+ const screenshotCount = payload.runs.reduce((sum, entry) => sum + entry.events.filter(event =>+ event.kind === 'screenshot' && (event.data?.screenshot_base64 || event.data?.screenshot_dataUrl)).length, 0);+ const traceType = screenshotCount > 0 || payload.runs.some(entry => entry.run.lossless === true+ || ['userMessage', 'finalContent', 'tabUrl', 'tabTitle'].some(key => entry.run[key])+ || entry.run.attachments?.length+ || entry.events.some(event => ['messages', 'result', 'args', 'content', 'text', 'message', 'reasoning', 'tools'].some(key => event.data?.[key])))+ ? 'full' : 'diagnostic';+ return {+ blob, originalBlob, filename, sessionId, traceType,+ runCount: payload.runs.length, screenshotCount,+ omissions: payload.feedbackOmissions,+ };+}diff --git a/src/chrome/src/trace/feedback-policy.js b/src/chrome/src/trace/feedback-policy.jsnew file mode 100644index 000000000..23a14f448--- /dev/null+++ b/src/chrome/src/trace/feedback-policy.js@@ -0,0 +1,33 @@+export const FEEDBACK_DIAGNOSTICS_KEY = 'feedbackDiagnosticsEnabled';+export const FEEDBACK_HISTORY_RUNS = 10;+export const FEEDBACK_HISTORY_AGE_MS = 7 * 24 * 60 * 60 * 1000;+export const FEEDBACK_HISTORY_BYTES = 2 * 1024 * 1024;+export const FEEDBACK_RUN_BYTES = 128 * 1024;++// Automatic diagnostics must never inherit a stale lossless preference.+export function feedbackRecordingPolicy(settings, forced = false) {+ const feedbackOnly = !forced && settings.tracingEnabled !== true+ && settings[FEEDBACK_DIAGNOSTICS_KEY] !== false;+ return {+ enabled: forced || settings.tracingEnabled === true || feedbackOnly,+ feedbackOnly,+ lossless: !feedbackOnly && settings.losslessTrace === true,+ };+}++export function feedbackRunsToEvict(runs, now = Date.now()) {+ const automatic = runs.filter(run => run.feedbackOnly === true);+ const completed = automatic.filter(run => run.status !== 'running')+ .sort((a, b) => (b.startedAt || 0) - (a.startedAt || 0));+ let bytes = automatic.filter(run => run.status === 'running')+ .reduce((sum, run) => sum + (Number(run.feedbackBytes) || 0), 0);+ let kept = 0;+ return completed.filter(run => {+ const size = Number(run.feedbackBytes) || 0;+ if (now - (run.startedAt || 0) > FEEDBACK_HISTORY_AGE_MS+ || kept >= FEEDBACK_HISTORY_RUNS || bytes + size > FEEDBACK_HISTORY_BYTES) return true;+ kept += 1;+ bytes += size;+ return false;+ }).map(run => run.runId);+}diff --git a/src/chrome/src/trace/recorder.js b/src/chrome/src/trace/recorder.jsindex 9f745a970..0c54ac9c6 100644--- a/src/chrome/src/trace/recorder.js+++ b/src/chrome/src/trace/recorder.js@@ -14,6 +14,7 @@ import {import { createTraceStats, addTraceEvent, aggregateTraceRuns } from './stats.js';import { projectTraceEventData, projectTraceRun } from './privacy.js';import { toolOutcome } from './tool-outcome.js';+import { feedbackRecordingPolicy, feedbackRunsToEvict, FEEDBACK_RUN_BYTES, FEEDBACK_HISTORY_BYTES } from './feedback-policy.js';/*** Trace recorder — writes per-run traces (LLM requests/responses, tool calls,@@ -25,9 +26,10 @@ import { toolOutcome } from './tool-outcome.js';* - shots keyPath=[runId, seq] // screenshot Blobs** All writes are fire-and-forget. Recording is gated on the `tracingEnabled`- * setting. When disabled, every call is a cheap no-op.+ * setting, explicit forced runs, or bounded automatic feedback diagnostics.*/+const traceStorage = () => (typeof browser !== 'undefined' ? browser : chrome).storage.local;const DB_NAME = 'webbrain_traces';const DB_VERSION = 2;@@ -96,29 +98,27 @@ function promisifyReq(req) {async function tracingEnabled() {try {if (typeof indexedDB === 'undefined') return false;- const { tracingEnabled } = await chrome.storage.local.get(['tracingEnabled']);+ const { tracingEnabled } = await traceStorage().get(['tracingEnabled']);return tracingEnabled === true;} catch { return false; }}-// Opt-in lossless tier: same event pipeline, full request payloads instead of-// content-free provenance. Read once per run at startRun; never per event.-async function losslessTraceEnabled() {- try {- if (typeof indexedDB === 'undefined') return false;- const { losslessTrace } = await chrome.storage.local.get(['losslessTrace']);- return losslessTrace === true;- } catch { return false; }-}-async function isForcedTraceRun(runId) {if (!runId) return false;+ if (_runState.get(runId)?.feedbackOnly === true) {+ const settings = await traceStorage().get('feedbackDiagnosticsEnabled');+ return settings.feedbackDiagnosticsEnabled !== false;+ }if (_runState.get(runId)?.forced === true) return true;try {const db = await openDB();const record = await promisifyReq(tx(db, ['runs'], 'readonly').objectStore('runs').get(runId),);+ if (record?.feedbackOnly === true) {+ const settings = await traceStorage().get('feedbackDiagnosticsEnabled');+ return settings.feedbackDiagnosticsEnabled !== false;+ }return record?.forced === true;} catch { return false; }}@@ -134,7 +134,7 @@ async function peekRunFlags(db, runId) {const record = await promisifyReq(tx(db, ['runs'], 'readonly').objectStore('runs').get(runId),);- return { forced: record?.forced === true, lossless: record?.lossless === true, losslessBytes: record?.losslessBytes || 0, losslessBytesEncoding: record?.losslessBytesEncoding || '' };+ return { forced: record?.forced === true, feedbackOnly: record?.feedbackOnly === true, feedbackBytes: record?.feedbackBytes || 0, lossless: record?.lossless === true, losslessBytes: record?.losslessBytes || 0, losslessBytesEncoding: record?.losslessBytesEncoding || '' };} catch { return { forced: false, lossless: false, losslessBytes: 0 }; }}@@ -199,7 +199,7 @@ async function _ensureRunState(runId, db = null) {const resolvedDb = db || await openDB();const seq = await _peekSeq(resolvedDb, runId);const flags = await peekRunFlags(resolvedDb, runId);- const state = { seq, forced: flags.forced, lossless: flags.lossless, losslessBytes: Number(flags.losslessBytes) || 0, losslessBytesEncoding: flags.losslessBytesEncoding };+ const state = { seq, forced: flags.forced, feedbackOnly: flags.feedbackOnly, feedbackBytes: flags.feedbackBytes, lossless: flags.lossless, losslessBytes: Number(flags.losslessBytes) || 0, losslessBytesEncoding: flags.losslessBytesEncoding };_runState.set(runId, state);return state;} catch { return null; }@@ -383,15 +383,18 @@ function normalizeTraceAttachments(attachments) {// ----- Public API ------------------------------------------------------------export async function startRun(meta = {}) {- const forced = meta.force === true;- if (!forced && !(await tracingEnabled())) return null;try {+ if (typeof indexedDB === 'undefined') return null;+ const settings = await traceStorage().get(['tracingEnabled', 'losslessTrace', 'feedbackDiagnosticsEnabled']);+ const policy = feedbackRecordingPolicy(settings, meta.force === true);+ if (!policy.enabled) return null;+ const forced = meta.force === true || policy.feedbackOnly;const db = await openDB();const runId = meta.runId || `run_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;const lineage = normalizeRunHeader(meta) || {};// Tier is decided once per run: explicit caller override wins, otherwise// the opt-in setting. Never forced for local runs by default.- const lossless = meta.lossless === true || await losslessTraceEnabled();+ const lossless = !policy.feedbackOnly && (meta.lossless === true || policy.lossless);const record = projectTraceRun({runId,// Stable per-conversation id so the Traces UI can group sibling runs@@ -421,6 +424,7 @@ export async function startRun(meta = {}) {attachments: normalizeTraceAttachments(meta.attachments),...(lossless ? { lossless: true, losslessBytes: 0, losslessBytesEncoding: 'utf8' } : {}),forced,+ ...(policy.feedbackOnly ? { feedbackOnly: true, feedbackHistoryOmitted: true, feedbackBytes: 0 } : {}),stepCount: 0,totalInputTokens: 0,totalOutputTokens: 0,@@ -434,8 +438,31 @@ export async function startRun(meta = {}) {totalToolLatencyMs: 0,finalContent: null,}, { includeContent: lossless });- await promisifyReq(tx(db, ['runs']).objectStore('runs').put(record));- _runState.set(runId, { seq: 0, model: record.model, providerId: record.providerId, forced, lossless, losslessBytes: 0, losslessBytesEncoding: lossless ? 'utf8' : '' });+ if (policy.feedbackOnly) {+ await pruneFeedbackDiagnostics();+ // Reserve room for final statistics and omission flags as well as events.+ record.feedbackBytes = utf8ByteLength(JSON.stringify(record)) + 1024;+ }+ if (policy.feedbackOnly) {+ const saved = await new Promise((resolve, reject) => {+ const transaction = tx(db, ['runs']);+ const store = transaction.objectStore('runs');+ const request = store.getAll();+ let inserted = false;+ request.onsuccess = () => {+ const total = request.result.filter(row => row.feedbackOnly)+ .reduce((sum, row) => sum + (Number(row.feedbackBytes) || 0), 0);+ if (record.feedbackBytes > FEEDBACK_RUN_BYTES+ || total + record.feedbackBytes > FEEDBACK_HISTORY_BYTES - 4096) return;+ store.put(record); inserted = true;+ };+ transaction.oncomplete = () => resolve(inserted);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error);+ });+ if (!saved) return null;+ } else await promisifyReq(tx(db, ['runs']).objectStore('runs').put(record));+ _runState.set(runId, { seq: 0, model: record.model, providerId: record.providerId, forced, feedbackOnly: policy.feedbackOnly, feedbackBytes: record.feedbackBytes || 0, lossless, losslessBytes: 0, losslessBytesEncoding: lossless ? 'utf8' : '' });_workflowTraceCaptures.set(runId, {run: {runId,@@ -535,6 +562,9 @@ async function _appendEventNow(runId, kind, data) {console.warn('[trace] dropped invalid event:', kind);return null;}+ if (state?.feedbackOnly === true) {+ return await writeFeedbackEvent(db, runId, ev, state);+ }if (state?.lossless === true && (kind === 'llm_request' || kind === 'tool')) {if (losslessBudgetOmitted) {await promisifyReq(tx(db, ['events']).objectStore('events').put(ev));@@ -559,6 +589,58 @@ async function _appendEventNow(runId, kind, data) {}}+let _feedbackWriteQueue = Promise.resolve();++// Serialize the shared byte budget across concurrently running tabs.+function writeFeedbackEvent(db, runId, event, state) {+ const pending = _feedbackWriteQueue.catch(() => {}).then(async () => {+ const bytes = utf8ByteLength(JSON.stringify(event));+ return new Promise((resolve, reject) => {+ const transaction = tx(db, ['runs', 'events']);+ const store = transaction.objectStore('runs');+ // Read the budget and write the event in one transaction. Other+ // extension contexts can prune/start runs without invalidating a cache.+ const request = store.getAll();+ let saved = false;+ request.onsuccess = () => {+ const run = request.result.find(row => row.runId === runId);+ const total = request.result.filter(row => row.feedbackOnly)+ .reduce((sum, row) => sum + (Number(row.feedbackBytes) || 0), 0);+ if (!run?.feedbackOnly) return;+ // Reserve a little space for final statistics and omission flags.+ if ((run.feedbackBytes || 0) + bytes > FEEDBACK_RUN_BYTES+ || total + bytes > FEEDBACK_HISTORY_BYTES - 4096) {+ run.feedbackEventsOmitted = true;+ store.put(run);+ return;+ }+ run.feedbackBytes = (run.feedbackBytes || 0) + bytes;+ store.put(run);+ transaction.objectStore('events').put(event);+ saved = true;+ };+ transaction.oncomplete = () => {+ if (saved) state.feedbackBytes += bytes;+ resolve(saved ? event.seq : null);+ };+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback diagnostic write aborted.'));+ });+ });+ _feedbackWriteQueue = pending;+ return pending;+}++export async function pruneFeedbackDiagnostics({ clear = false, now = Date.now() } = {}) {+ if (typeof indexedDB === 'undefined') return;+ const db = await openDB();+ const rows = await promisifyReq(tx(db, ['runs'], 'readonly').objectStore('runs').getAll());+ const ids = clear ? rows.filter(run => run.feedbackOnly === true).map(run => run.runId)+ : [...new Set([...feedbackRunsToEvict(rows, now), ...rows.filter(run => run.feedbackOnly === true+ && now - (run.startedAt || 0) > 7 * 24 * 60 * 60 * 1000).map(run => run.runId)])];+ for (const id of ids) { await deleteRun(id); if (clear) _runState.delete(id); }+}+// Retain the active run and evict completed lossless runs oldest first when// their aggregate recorded payload crosses the global budget. A cached running// total keeps under-budget writes free of any store-wide scan; the scan itself@@ -826,6 +908,7 @@ export function recordScreenshot(runId, step, dataUrl, caption = '') {projectTraceEventData('screenshot', { step, caption }, { includeContent: state?.lossless === true }),);if (marker) {+ if (state?.feedbackOnly === true) return await writeFeedbackEvent(db, runId, marker, state);await promisifyReq(tx(db, ['events']).objectStore('events').put(marker));}return seq;@@ -1014,8 +1097,11 @@ export async function endRun(runId, { status = 'done', finalContent = null } = {} finally {_runState.delete(runId);}+ // Retention may delete this run and its transient capture. Keep the+ // completed workflow independent of which diagnostics remain on disk.const workflowCapture = _workflowTraceCaptures.get(runId) || null;_workflowTraceCaptures.delete(runId);+ await pruneFeedbackDiagnostics().catch(() => {});if (!workflowCapture) return null;workflowCapture.run.status = resolvedStatus;return { run: workflowCapture.run, events: workflowCapture.events };@@ -1088,6 +1174,7 @@ export async function flushPendingWrites() {}export async function listRuns({ limit = 500, conversationId = null } = {}) {+ await pruneFeedbackDiagnostics();const db = await openDB();const store = tx(db, ['runs'], 'readonly').objectStore('runs');const sessionQuery = Boolean(conversationId && store.indexNames.contains('sessionId'));diff --git a/src/chrome/src/ui/feedback-consent.css b/src/chrome/src/ui/feedback-consent.cssnew file mode 100644index 000000000..2b1972a1c--- /dev/null+++ b/src/chrome/src/ui/feedback-consent.css@@ -0,0 +1,14 @@+.feedback-trace-dialog {+ margin: auto;+ width: min(440px, calc(100vw - 48px)); max-height: calc(100vh - 48px);+ overflow: auto; padding: 20px; border: 1px solid var(--border, #8886);+ border-radius: 12px; background: var(--bg-secondary, Canvas); color: var(--text-primary, CanvasText);+ font: inherit; box-shadow: 0 12px 48px #0005;+}+.feedback-trace-dialog::backdrop { background: #0008; }+.feedback-trace-dialog h2 { font-size: 18px; margin: 0 0 12px; }+.feedback-trace-dialog p { line-height: 1.5; margin: 0 0 12px; }+.feedback-trace-details { overflow-wrap: anywhere; font-size: 12px; }+.feedback-trace-actions { display: grid; gap: 8px; }+.feedback-trace-actions button { white-space: normal; }+.feedback-trace-secondary { padding: 9px; border: 1px solid #8886; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }diff --git a/src/chrome/src/ui/feedback-consent.js b/src/chrome/src/ui/feedback-consent.jsnew file mode 100644index 000000000..0613ac470--- /dev/null+++ b/src/chrome/src/ui/feedback-consent.js@@ -0,0 +1,63 @@+import { formatFeedbackDetails } from './feedback-copy.js';++export function requestFeedbackConsent(trace, copy, viewTrace) {+ return new Promise(resolve => {+ const dialog = document.createElement('dialog');+ dialog.className = 'feedback-trace-dialog';+ dialog.setAttribute('aria-labelledby', 'feedback-trace-title');+ dialog.setAttribute('aria-describedby', 'feedback-trace-public');+ const previousFocus = document.activeElement;+ const text = (tag, value, id = '') => {+ const element = document.createElement(tag); element.textContent = value;+ if (id) element.id = id;+ dialog.append(element); return element;+ };+ text('h2', copy.title, 'feedback-trace-title');+ text('p', copy.publicWarning, 'feedback-trace-public');+ text('p', copy[trace.traceType]);+ text('p', formatFeedbackDetails(trace, copy)).className = 'feedback-trace-details';+ if (trace.omissions.length) text('p', trace.blob !== trace.originalBlob && trace.filename.endsWith('-diagnostics.json') ? copy.oversized : copy.omitted);+ const actions = text('div', ''); actions.className = 'feedback-trace-actions';+ const finish = choice => { dialog.close(); dialog.remove(); previousFocus?.focus(); resolve(choice); };+ for (const [choice, label] of [['view', copy.view], ['upload', copy.upload], ['without', copy.without], ['cancel', copy.cancel]]) {+ const button = document.createElement('button'); button.type = 'button'; button.textContent = label;+ button.dataset.feedbackChoice = choice;+ button.className = choice === 'upload' ? 'store-review-primary' : 'feedback-trace-secondary';+ button.addEventListener('click', () => choice === 'view' ? void viewTrace().catch(error => {+ text('p', error.message).setAttribute('role', 'alert');+ }) : finish(choice));+ actions.append(button);+ }+ dialog.addEventListener('cancel', event => { event.preventDefault(); finish('cancel'); });+ dialog.addEventListener('keydown', event => event.stopPropagation());+ document.body.append(dialog); dialog.showModal();+ actions.querySelector('[data-feedback-choice="cancel"]').focus();+ });+}++// The only call capable of opening the upload destination is after consent.+export async function submitFeedbackWithTrace({ prepare, stage, consent, discard, open, rating, comment, copy }) {+ let prepared, staged, traceNote = '', handedOff = false;+ try { prepared = await prepare(); } catch { traceNote = copy.exportFailed; }+ if (!prepared) {+ await open({ rating, comment, includeTrace: false, traceNote: traceNote || copy.unavailable, copy });+ return true;+ }+ staged = await stage(prepared);+ try {+ const choice = await consent(prepared, staged);+ if (choice === 'cancel') return false;+ const includeTrace = choice === 'upload';+ if (!includeTrace) await discard(staged.id);+ await open({ id: staged.id, rating, comment, includeTrace, copy,+ traceNote: includeTrace ? `${copy[`${prepared.traceType}Label`]} (${prepared.runCount} runs, ${prepared.screenshotCount} screenshots).`+ + (prepared.omissions.length ? ` ${copy.omitted}` : '') : '' });+ handedOff = includeTrace;+ return true;+ } catch (error) {+ await discard(staged.id); throw error;+ } finally {+ // The background owns an accepted handoff; keep its immutable bytes for retries.+ if (!handedOff) await discard(staged.id);+ }+}diff --git a/src/chrome/src/ui/feedback-copy.js b/src/chrome/src/ui/feedback-copy.jsnew file mode 100644index 000000000..e35f22615--- /dev/null+++ b/src/chrome/src/ui/feedback-copy.js@@ -0,0 +1,107 @@+const EN = {+ title: 'Share this trace on GitHub?',+ publicWarning: 'Uploading makes this file publicly accessible immediately, even if you never submit the GitHub issue.',+ full: 'Includes recorded conversation text, tool details, and any saved screenshots. Screenshots may contain private information. Obvious credentials are masked; review the trace before sharing.',+ diagnostic: 'Includes diagnostic metadata: tool names, outcomes, error codes, and timings. Conversation text and screenshots that were not recorded are unavailable.',+ upload: 'Upload trace and open GitHub', without: 'Continue without trace', cancel: 'Cancel', view: 'View trace',+ fullLabel: 'Full recorded trace', diagnosticLabel: 'Diagnostic trace',+ details: 'Conversation {session} · {type} · {runs} runs · {shots} screenshots · {size}',+ preparing: 'Preparing trace locally…',+ omitted: 'Recording or retention limits omitted some content. See the trace for details.',+ oversized: 'The full export is too large to attach. Only the diagnostic fallback will be uploaded. View trace to download the full export locally.',+ failed: 'The trace attachment could not be confirmed. Check the draft before retrying, or download the trace.',+ uploading: 'Attaching your trace. Please wait before submitting the issue.',+ ready: 'Trace attached. Review and submit your feedback on GitHub.',+ draftReady: 'Review and submit your feedback on GitHub.',+ retry: 'Retry attachment', download: 'Download trace', close: 'Close',+ local: 'Local preview. Nothing is uploaded by viewing or downloading this trace.',+ original: 'Download full export', previewLimited: 'Preview shortened. Download the export to inspect the complete file.',+ unavailable: 'No recorded trace is available for this conversation.',+ exportFailed: 'The trace could not be read; no trace is attached.',+ settingLabel: 'Local feedback diagnostics',+ settingDescription: 'Keep recent diagnostic metadata locally, even when Record traces is off. Limited to 10 completed runs, 7 days, and 2 MiB. Upload requires confirmation when sending feedback; conversation text and screenshots are not recorded by this option.',+};++// Keep the consequential disclosure and actions translated for every UI locale.+// Secondary status text uses the same English fallback as the main UI.+const CORE = {+ ru: ['Поделиться этой трассировкой на GitHub?', 'Файл станет общедоступным сразу после загрузки, даже если вы не отправите обращение на GitHub.', 'Загрузить трассировку и открыть GitHub', 'Продолжить без трассировки', 'Отмена', 'Посмотреть трассировку'],+ ar: ['مشاركة هذا التتبع على GitHub؟', 'يصبح هذا الملف متاحًا للجميع فور رفعه، حتى لو لم ترسل المشكلة على GitHub.', 'رفع التتبع وفتح GitHub', 'المتابعة دون تتبع', 'إلغاء', 'عرض التتبع'],+ bn: ['এই ট্রেস GitHub-এ শেয়ার করবেন?', 'আপলোড করলেই ফাইলটি সবার জন্য উন্মুক্ত হবে, আপনি GitHub ইস্যু জমা না দিলেও।', 'ট্রেস আপলোড করে GitHub খুলুন', 'ট্রেস ছাড়া চালিয়ে যান', 'বাতিল', 'ট্রেস দেখুন'],+ de: ['Diesen Trace auf GitHub teilen?', 'Die Datei ist sofort nach dem Hochladen öffentlich zugänglich, auch wenn du das GitHub-Issue nie absendest.', 'Trace hochladen und GitHub öffnen', 'Ohne Trace fortfahren', 'Abbrechen', 'Trace ansehen'],+ es: ['¿Compartir esta traza en GitHub?', 'El archivo será público inmediatamente al subirlo, aunque nunca envíes la incidencia de GitHub.', 'Subir traza y abrir GitHub', 'Continuar sin traza', 'Cancelar', 'Ver traza'],+ fa: ['این ردگیری در GitHub به اشتراک گذاشته شود؟', 'فایل بلافاصله پس از بارگذاری برای همه قابل دسترسی میشود، حتی اگر گزارش GitHub را ارسال نکنید.', 'بارگذاری ردگیری و باز کردن GitHub', 'ادامه بدون ردگیری', 'لغو', 'مشاهده ردگیری'],+ fr: ['Partager cette trace sur GitHub ?', 'Le fichier devient public dès son téléversement, même si vous ne soumettez jamais le ticket GitHub.', 'Téléverser la trace et ouvrir GitHub', 'Continuer sans trace', 'Annuler', 'Voir la trace'],+ he: ['לשתף את התיעוד הזה ב-GitHub?', 'הקובץ יהיה נגיש לציבור מיד לאחר ההעלאה, גם אם לא תשלחו את הדיווח ב-GitHub.', 'העלאת התיעוד ופתיחת GitHub', 'המשך ללא תיעוד', 'ביטול', 'הצגת התיעוד'],+ hi: ['यह ट्रेस GitHub पर साझा करें?', 'अपलोड होते ही फ़ाइल सार्वजनिक हो जाएगी, भले ही आप GitHub समस्या कभी जमा न करें।', 'ट्रेस अपलोड करें और GitHub खोलें', 'ट्रेस के बिना जारी रखें', 'रद्द करें', 'ट्रेस देखें'],+ id: ['Bagikan trace ini di GitHub?', 'Berkas langsung dapat diakses publik setelah diunggah, meskipun Anda tidak pernah mengirim issue GitHub.', 'Unggah trace dan buka GitHub', 'Lanjutkan tanpa trace', 'Batal', 'Lihat trace'],+ ja: ['このトレースをGitHubで共有しますか?', 'アップロードすると、GitHubのIssueを送信しなくても、ファイルは直ちに公開されます。', 'トレースをアップロードしてGitHubを開く', 'トレースなしで続行', 'キャンセル', 'トレースを表示'],+ ko: ['이 트레이스를 GitHub에 공유할까요?', '업로드하면 GitHub 이슈를 제출하지 않아도 파일이 즉시 공개됩니다.', '트레이스 업로드 후 GitHub 열기', '트레이스 없이 계속', '취소', '트레이스 보기'],+ ms: ['Kongsi jejak ini di GitHub?', 'Fail boleh diakses umum serta-merta selepas dimuat naik, walaupun anda tidak menghantar isu GitHub.', 'Muat naik jejak dan buka GitHub', 'Teruskan tanpa jejak', 'Batal', 'Lihat jejak'],+ nl: ['Deze trace op GitHub delen?', 'Het bestand is direct na het uploaden openbaar, ook als je het GitHub-issue nooit indient.', 'Trace uploaden en GitHub openen', 'Doorgaan zonder trace', 'Annuleren', 'Trace bekijken'],+ pl: ['Udostępnić ten ślad na GitHub?', 'Plik stanie się publicznie dostępny natychmiast po przesłaniu, nawet jeśli nie wyślesz zgłoszenia GitHub.', 'Prześlij ślad i otwórz GitHub', 'Kontynuuj bez śladu', 'Anuluj', 'Zobacz ślad'],+ pt: ['Compartilhar este rastreamento no GitHub?', 'O arquivo ficará público imediatamente após o envio, mesmo que você nunca publique a issue no GitHub.', 'Enviar rastreamento e abrir GitHub', 'Continuar sem rastreamento', 'Cancelar', 'Ver rastreamento'],+ th: ['แชร์บันทึกนี้บน GitHub หรือไม่?', 'ไฟล์จะเปิดให้สาธารณะเข้าถึงได้ทันทีที่อัปโหลด แม้คุณจะไม่ส่งปัญหาบน GitHub ก็ตาม', 'อัปโหลดบันทึกและเปิด GitHub', 'ดำเนินการต่อโดยไม่แนบบันทึก', 'ยกเลิก', 'ดูบันทึก'],+ tl: ['Ibahagi ang trace na ito sa GitHub?', 'Magiging pampubliko agad ang file kapag na-upload, kahit hindi mo isumite ang GitHub issue.', 'I-upload ang trace at buksan ang GitHub', 'Magpatuloy nang walang trace', 'Kanselahin', 'Tingnan ang trace'],+ tr: ['Bu izi GitHub’da paylaşmak ister misiniz?', 'Dosya yüklendiği anda herkese açık olur; GitHub sorununu göndermeseniz bile dosyaya erişilebilir.', 'İzi yükle ve GitHub’ı aç', 'İz olmadan devam et', 'İptal', 'İzi görüntüle'],+ uk: ['Поділитися цим трасуванням на GitHub?', 'Файл стане загальнодоступним одразу після завантаження, навіть якщо ви не надішлете звернення на GitHub.', 'Завантажити трасування й відкрити GitHub', 'Продовжити без трасування', 'Скасувати', 'Переглянути трасування'],+ vi: ['Chia sẻ dấu vết này trên GitHub?', 'Tệp sẽ công khai ngay khi tải lên, kể cả khi bạn không gửi vấn đề trên GitHub.', 'Tải dấu vết lên và mở GitHub', 'Tiếp tục không kèm dấu vết', 'Hủy', 'Xem dấu vết'],+ zh: ['在 GitHub 上分享此跟踪记录?', '上传后文件会立即公开,即使您最终没有提交 GitHub 问题。', '上传跟踪记录并打开 GitHub', '不附带跟踪记录继续', '取消', '查看跟踪记录'],+};+const CONTENT = {+ ar: ['يتضمن نص المحادثة وتفاصيل الأدوات ولقطات الشاشة المحفوظة، إن وُجدت. تُخفى بيانات الاعتماد الواضحة؛ راجع الملف قبل مشاركته.', 'يتضمن بيانات تشخيصية فقط: أسماء الأدوات والنتائج ورموز الأخطاء والتوقيتات. لا تتوفر النصوص أو الصور غير المسجلة.'],+ bn: ['সংরক্ষিত কথোপকথন, টুলের বিবরণ ও উপলব্ধ স্ক্রিনশট অন্তর্ভুক্ত থাকে। স্পষ্ট পরিচয়পত্র গোপন করা হয়; শেয়ার করার আগে ফাইলটি দেখুন।', 'শুধু ডায়াগনস্টিক তথ্য থাকে: টুলের নাম, ফলাফল, ত্রুটি কোড ও সময়। রেকর্ড না করা লেখা বা স্ক্রিনশট নেই।'],+ de: ['Enthält aufgezeichnete Gespräche, Werkzeugdetails und vorhandene Screenshots. Offensichtliche Zugangsdaten werden maskiert; prüfe die Datei vor dem Teilen.', 'Enthält nur Diagnosedaten: Werkzeugnamen, Ergebnisse, Fehlercodes und Zeitangaben. Nicht aufgezeichnete Texte und Screenshots sind nicht verfügbar.'],+ es: ['Incluye conversaciones grabadas, detalles de herramientas y capturas disponibles. Se ocultan las credenciales evidentes; revisa el archivo antes de compartirlo.', 'Solo incluye datos de diagnóstico: nombres de herramientas, resultados, códigos de error y tiempos. Los textos y capturas no grabados no están disponibles.'],+ fa: ['شامل گفتوگوی ثبتشده، جزئیات ابزارها و تصاویر ذخیرهشده است. اطلاعات ورود آشکار پوشانده میشوند؛ پیش از اشتراکگذاری فایل را بررسی کنید.', 'فقط شامل اطلاعات تشخیصی است: نام ابزارها، نتایج، کدهای خطا و زمانها. متن و تصاویر ثبتنشده موجود نیستند.'],+ he: ['כולל שיחות שהוקלטו, פרטי כלים וצילומי מסך זמינים. פרטי גישה ברורים מוסתרים; בדקו את הקובץ לפני השיתוף.', 'כולל רק נתוני אבחון: שמות כלים, תוצאות, קודי שגיאה וזמנים. טקסט ותמונות שלא תועדו אינם זמינים.'],+ hi: ['रिकॉर्ड की गई बातचीत, टूल विवरण और उपलब्ध स्क्रीनशॉट शामिल हैं। स्पष्ट लॉगिन जानकारी छिपाई जाती है; साझा करने से पहले फ़ाइल देखें।', 'केवल निदान जानकारी: टूल के नाम, परिणाम, त्रुटि कोड और समय। रिकॉर्ड न किया गया पाठ या स्क्रीनशॉट उपलब्ध नहीं है।'],+ id: ['Berisi percakapan yang direkam, detail alat, dan tangkapan layar yang tersedia. Kredensial yang jelas disamarkan; periksa berkas sebelum berbagi.', 'Hanya berisi diagnostik: nama alat, hasil, kode kesalahan, dan waktu. Teks dan tangkapan layar yang tidak direkam tidak tersedia.'],+ ja: ['記録された会話、ツールの詳細、保存済みのスクリーンショットを含みます。明らかな認証情報はマスクされます。共有前にファイルを確認してください。', 'ツール名、結果、エラーコード、時間などの診断情報のみを含みます。記録されていない会話やスクリーンショットは含まれません。'],+ ko: ['기록된 대화, 도구 세부 정보 및 저장된 스크린샷을 포함합니다. 명백한 인증 정보는 가려집니다. 공유하기 전에 파일을 확인하세요.', '도구 이름, 결과, 오류 코드 및 시간 등 진단 정보만 포함합니다. 기록하지 않은 대화나 스크린샷은 제공되지 않습니다.'],+ ms: ['Mengandungi perbualan yang direkodkan, butiran alat dan tangkapan skrin yang tersedia. Bukti kelayakan yang jelas disamarkan; semak fail sebelum berkongsi.', 'Hanya mengandungi diagnostik: nama alat, hasil, kod ralat dan masa. Teks dan tangkapan skrin yang tidak direkodkan tidak tersedia.'],+ nl: ['Bevat opgenomen gesprekken, tooldetails en beschikbare schermafbeeldingen. Duidelijke inloggegevens worden afgeschermd; controleer het bestand voordat je het deelt.', 'Bevat alleen diagnostiek: toolnamen, resultaten, foutcodes en tijden. Niet opgenomen tekst en schermafbeeldingen zijn niet beschikbaar.'],+ pl: ['Zawiera zapisane rozmowy, szczegóły narzędzi i dostępne zrzuty ekranu. Oczywiste dane logowania są maskowane; sprawdź plik przed udostępnieniem.', 'Zawiera tylko diagnostykę: nazwy narzędzi, wyniki, kody błędów i czasy. Niezapisane teksty i zrzuty ekranu nie są dostępne.'],+ pt: ['Inclui conversas gravadas, detalhes de ferramentas e capturas disponíveis. Credenciais evidentes são ocultadas; revise o arquivo antes de compartilhar.', 'Inclui apenas diagnóstico: nomes de ferramentas, resultados, códigos de erro e tempos. Textos e capturas não gravados não estão disponíveis.'],+ ru: ['Содержит записанные разговоры, детали инструментов и сохранённые снимки экрана. Очевидные учётные данные маскируются; проверьте файл перед отправкой.', 'Содержит только диагностику: имена инструментов, результаты, коды ошибок и время. Незаписанный текст и снимки экрана недоступны.'],+ th: ['รวมบทสนทนาที่บันทึกไว้ รายละเอียดเครื่องมือ และภาพหน้าจอที่มีอยู่ ข้อมูลรับรองที่ชัดเจนจะถูกปิดบัง โปรดตรวจสอบไฟล์ก่อนแชร์', 'มีเฉพาะข้อมูลวินิจฉัย: ชื่อเครื่องมือ ผลลัพธ์ รหัสข้อผิดพลาด และเวลา ไม่มีข้อความหรือภาพหน้าจอที่ไม่ได้บันทึกไว้'],+ tl: ['Kasama ang naitalang usapan, detalye ng mga tool, at available na screenshot. Itinatago ang malinaw na kredensyal; suriin ang file bago ibahagi.', 'Diagnostic data lamang: pangalan ng mga tool, resulta, error code, at oras. Walang tekstong o screenshot na hindi naitala.'],+ uk: ['Містить записані розмови, деталі інструментів і збережені знімки екрана. Очевидні облікові дані маскуються; перевірте файл перед надсиланням.', 'Містить лише діагностику: назви інструментів, результати, коди помилок і час. Незаписаний текст і знімки екрана недоступні.'],+ vi: ['Gồm cuộc trò chuyện đã ghi, chi tiết công cụ và ảnh chụp màn hình có sẵn. Thông tin đăng nhập rõ ràng được che; hãy xem tệp trước khi chia sẻ.', 'Chỉ gồm chẩn đoán: tên công cụ, kết quả, mã lỗi và thời gian. Văn bản và ảnh chụp chưa ghi không có sẵn.'],+ zh: ['包含已记录的对话、工具详情和已保存的截图。明显的凭据会被遮盖;分享前请检查文件。', '仅包含诊断信息:工具名称、结果、错误代码和时间。未记录的对话文本和截图不可用。'],+};+const EXTRA = {+ tr: {+ full: 'Kaydedilmiş konuşma metni, araç ayrıntıları ve varsa ekran görüntülerini içerir. Ekran görüntülerinde özel bilgiler olabilir. Belirgin kimlik bilgileri maskelenir; paylaşmadan önce izi inceleyin.',+ diagnostic: 'Araç adları, sonuçlar, hata kodları ve süreler gibi tanılama bilgilerini içerir. Kaydedilmemiş konuşma metni ve ekran görüntüleri mevcut değildir.',+ fullLabel: 'Tam kaydedilmiş iz', diagnosticLabel: 'Tanılama izi',+ details: 'Konuşma {session} · {type} · {runs} çalışma · {shots} ekran görüntüsü · {size}',+ preparing: 'İz yerel olarak hazırlanıyor…', settingLabel: 'Yerel geri bildirim tanılaması',+ settingDescription: 'İz kaydı kapalı olsa da son tanılama bilgilerini cihazda saklar. En fazla 10 tamamlanan çalışma, 7 gün ve 2 MiB. Geri bildirim gönderirken yükleme için onay gerekir; bu seçenek konuşma metni veya ekran görüntüsü kaydetmez.',+ },+ fr: {+ full: 'Contient le texte de conversation enregistré, les détails des outils et les captures conservées. Les captures peuvent contenir des informations privées. Les identifiants évidents sont masqués ; vérifiez la trace avant de la partager.',+ diagnostic: 'Contient les noms des outils, les résultats, les codes d’erreur et les durées. Le texte et les captures non enregistrés ne sont pas disponibles.',+ fullLabel: 'Trace enregistrée complète', diagnosticLabel: 'Trace de diagnostic',+ details: 'Conversation {session} · {type} · {runs} exécutions · {shots} captures · {size}',+ },+};+export function getFeedbackCopy(locale = 'en') {+ const copy = { ...EN, ...EXTRA[locale] };+ if (CORE[locale]) ['title', 'publicWarning', 'upload', 'without', 'cancel', 'view'].forEach((key, index) => { copy[key] = CORE[locale][index]; });+ if (CONTENT[locale]) [copy.full, copy.diagnostic] = CONTENT[locale];+ return copy;+}+export function formatFeedbackDetails(trace, copy) {+ const values = { session: trace.sessionId, type: copy[`${trace.traceType}Label`],+ runs: trace.runCount, shots: trace.screenshotCount, size: `${(trace.blob.size / 1024).toFixed(1)} KiB` };+ return copy.details.replace(/\{(\w+)\}/g, (_, key) => values[key] ?? '');+}++export const feedbackTranslations = Object.fromEntries(['en', ...Object.keys(CORE)].map(locale => {+ const copy = getFeedbackCopy(locale);+ return [locale, {+ 'st.display.feedback_diagnostics.label': copy.settingLabel,+ 'st.display.feedback_diagnostics.desc': copy.settingDescription,+ }];+}));diff --git a/src/chrome/src/ui/feedback-trace-preview.css b/src/chrome/src/ui/feedback-trace-preview.cssnew file mode 100644index 000000000..276b23d6a--- /dev/null+++ b/src/chrome/src/ui/feedback-trace-preview.css@@ -0,0 +1,4 @@+:root { color-scheme: light dark; font: 15px/1.5 system-ui; }+body { margin: 24px; } main { max-width: 1100px; margin: auto; }+pre { white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid #8886; padding: 16px; border-radius: 8px; }+button { padding: 8px 16px; margin-right: 8px; cursor: pointer; }diff --git a/src/chrome/src/ui/feedback-trace-preview.html b/src/chrome/src/ui/feedback-trace-preview.htmlnew file mode 100644index 000000000..e9244c625--- /dev/null+++ b/src/chrome/src/ui/feedback-trace-preview.html@@ -0,0 +1,7 @@+<!doctype html>+<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">+<title>WebBrain trace preview</title><script src="theme-bootstrap.js"></script>+<link rel="stylesheet" href="feedback-trace-preview.css"></head>+<body><main><h1 id="title">WebBrain trace preview</h1><p id="notice"></p><p id="details"></p>+<button type="button" id="download"></button><button type="button" id="download-original" hidden></button>+<p id="limit"></p><pre id="preview"></pre></main><script type="module" src="feedback-trace-preview.js"></script></body></html>diff --git a/src/chrome/src/ui/feedback-trace-preview.js b/src/chrome/src/ui/feedback-trace-preview.jsnew file mode 100644index 000000000..a8afd9849--- /dev/null+++ b/src/chrome/src/ui/feedback-trace-preview.js@@ -0,0 +1,34 @@+import { getFeedbackDraft } from '../feedback-store.js';+import { getFeedbackCopy, formatFeedbackDetails } from './feedback-copy.js';+import { getLocale } from './i18n.js';++let copy = getFeedbackCopy(getLocale());+document.getElementById('title').textContent = copy.view;+document.getElementById('notice').textContent = copy.local;+function download(blob, filename) {+ const url = URL.createObjectURL(blob), anchor = document.createElement('a');+ anchor.href = url; anchor.download = filename; anchor.click();+ setTimeout(() => URL.revokeObjectURL(url), 1000);+}+try {+ const draft = await getFeedbackDraft(new URL(location.href).searchParams.get('id'));+ if (!draft?.blob || draft.expiresAt <= Date.now()) throw new Error(copy.unavailable);+ copy = draft.copy || copy;+ document.getElementById('title').textContent = copy.view;+ document.getElementById('notice').textContent = copy.local;+ document.getElementById('details').textContent = formatFeedbackDetails(draft, copy);+ // The original uncompressed JSON is retained only locally, including when+ // the consent dialog proposes a smaller diagnostic fallback.+ const previewBlob = draft.filename.endsWith('-diagnostics.json') ? draft.blob : draft.originalBlob;+ document.getElementById('preview').textContent = await previewBlob.slice(0, 500_000).text();+ if (previewBlob.size > 500_000) document.getElementById('limit').textContent = copy.previewLimited;+ const button = document.getElementById('download'); button.textContent = copy.download;+ button.addEventListener('click', () => download(draft.blob, draft.filename));+ if (draft.blob.size !== draft.originalBlob.size) {+ const original = document.getElementById('download-original'); original.hidden = false; original.textContent = copy.original;+ original.addEventListener('click', () => download(draft.originalBlob, 'webbrain-feedback-full.json'));+ }+} catch (error) {+ document.getElementById('preview').textContent = error.message;+ document.getElementById('download').hidden = true;+}diff --git a/src/chrome/src/ui/i18n.js b/src/chrome/src/ui/i18n.jsindex 7c7acb932..343332dbd 100644--- a/src/chrome/src/ui/i18n.js+++ b/src/chrome/src/ui/i18n.js@@ -4,6 +4,7 @@ import { decisionEnglish, decisionTranslations } from './locales/decision-copy.m// Works identically in Chrome MV3 and Firefox MV2.import en from './locales/en.js';+import { feedbackTranslations } from './feedback-copy.js';import { quotaTranslations } from './locales/compass-quota-copy.mjs';import { memcodeEnglish } from './locales/memcode-copy.mjs';import { captchaEnglish, captchaTranslations } from './locales/captcha-copy.mjs';@@ -38,6 +39,7 @@ import { pdfViewerEnglish } from './locales/pdf-viewer-copy.mjs';const DICTS = Object.fromEntries(Object.entries({ en, es, fr, tr, zh, ru, uk, ar, ja, ko, id, th, ms, tl, pl, he, hi, pt, vi, bn, fa, nl, de }).map(([code, dict]) => [code, {...dict,+ ...feedbackTranslations[code],...(composerDeliveryTranslations[code] || {}),...(cloudBridgeTranslations[code] || {}),...quotaTranslations[code],diff --git a/src/chrome/src/ui/settings.html b/src/chrome/src/ui/settings.htmlindex 631c315e8..4c2ddc551 100644--- a/src/chrome/src/ui/settings.html+++ b/src/chrome/src/ui/settings.html@@ -1666,6 +1666,16 @@<span class="toggle-slider"></span></label></div>+ <div class="setting-row">+ <div class="setting-info">+ <div class="setting-label" data-i18n="st.display.feedback_diagnostics.label"></div>+ <div class="setting-desc" data-i18n="st.display.feedback_diagnostics.desc"></div>+ </div>+ <label class="toggle">+ <input type="checkbox" id="toggle-feedback-diagnostics" checked>+ <span class="toggle-slider"></span>+ </label>+ </div><div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.display.verbose.label"></div>diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.jsindex 8ca2a85fc..3e715adaa 100644--- a/src/chrome/src/ui/settings.js+++ b/src/chrome/src/ui/settings.js@@ -136,6 +136,7 @@ const notifySoundToggle = document.getElementById('toggle-notify-sound');const completionConfettiToggle = document.getElementById('toggle-completion-confetti');const completionFlashTabToggle = document.getElementById('toggle-completion-flash-tab');const tracingToggle = document.getElementById('toggle-tracing');+const feedbackDiagnosticsToggle = document.getElementById('toggle-feedback-diagnostics');const losslessTracingToggle = document.getElementById('toggle-lossless-tracing');const strictSecretToggle = document.getElementById('toggle-strict-secret');const allowLocalNetworkToggle = document.getElementById('toggle-allow-local-network');@@ -624,7 +625,7 @@ async function init() {chrome.storage.local.remove(['authToken', 'authEmail', 'authDefaultModel']).catch(() => {});// Load display settings- const stored = await chrome.storage.local.get([...DECISION_SETTINGS_KEYS, 'verboseMode', 'composerDeliveryMode', 'selectionShortcutEnabled', 'pdfViewerEnabled', AUTO_GROUP_TABS_KEY, 'helpImproveWebBrain', 'screenshotFallback', 'maxAgentSteps', 'autoScreenshot', 'useSiteAdapters', 'researchEscalationEnabled', 'researchEscalationEngine', 'voiceInputEnabled', 'alwaysAllowApiMutations', 'apiMutationObserverEnabled', 'webMcpEnabled', 'openaiAskStreamingEnabled', 'planBeforeActMode', 'planBeforeAct', 'planReviewMode', 'planReviewConfidenceThreshold', DOWNLOAD_DIRECTORY_STORAGE_KEY, 'notifySound', 'completionConfetti', 'completionFlashTab', 'tracingEnabled', 'losslessTrace', 'strictSecretMode', 'agentAllowLocalNetwork', 'scheduledTasksEnabled', 'scheduledRequireConsequentialConfirmation', 'systemOneEnabled', 'systemOneWatchEnabled', 'systemOneCompletionEnabled', 'systemOneFastClassifications', 'systemOneFastBrowser', 'systemOneWatchThreshold', 'systemOneCompletionThreshold', 'typesafeApiKey', 'providerFilter', 'requestTimeoutMs', 'clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'costAllowanceSessionUsd', 'costAllowanceTotalUsd', 'meteredProviderCostSpentUsd', 'screenshotRedaction', 'imageDetail', 'maxScreenshotsPerTurn', 'maxImageDimension']);+ const stored = await chrome.storage.local.get([...DECISION_SETTINGS_KEYS, 'verboseMode', 'composerDeliveryMode', 'selectionShortcutEnabled', 'pdfViewerEnabled', AUTO_GROUP_TABS_KEY, 'helpImproveWebBrain', 'screenshotFallback', 'maxAgentSteps', 'autoScreenshot', 'useSiteAdapters', 'researchEscalationEnabled', 'researchEscalationEngine', 'voiceInputEnabled', 'alwaysAllowApiMutations', 'apiMutationObserverEnabled', 'webMcpEnabled', 'openaiAskStreamingEnabled', 'planBeforeActMode', 'planBeforeAct', 'planReviewMode', 'planReviewConfidenceThreshold', DOWNLOAD_DIRECTORY_STORAGE_KEY, 'notifySound', 'completionConfetti', 'completionFlashTab', 'tracingEnabled', 'feedbackDiagnosticsEnabled', 'losslessTrace', 'strictSecretMode', 'agentAllowLocalNetwork', 'scheduledTasksEnabled', 'scheduledRequireConsequentialConfirmation', 'systemOneEnabled', 'systemOneWatchEnabled', 'systemOneCompletionEnabled', 'systemOneFastClassifications', 'systemOneFastBrowser', 'systemOneWatchThreshold', 'systemOneCompletionThreshold', 'typesafeApiKey', 'providerFilter', 'requestTimeoutMs', 'clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'costAllowanceSessionUsd', 'costAllowanceTotalUsd', 'meteredProviderCostSpentUsd', 'screenshotRedaction', 'imageDetail', 'maxScreenshotsPerTurn', 'maxImageDimension']);if (typeof stored.providerFilter === 'string' && ['all','active','local','cloud','router'].includes(stored.providerFilter)) {providerFilter = stored.providerFilter;}@@ -701,6 +702,7 @@ async function init() {completionConfettiToggle.checked = stored.completionConfetti ?? true; // on by defaultcompletionFlashTabToggle.checked = stored.completionFlashTab ?? true; // on by defaulttracingToggle.checked = stored.tracingEnabled === true;+ if (feedbackDiagnosticsToggle) feedbackDiagnosticsToggle.checked = stored.feedbackDiagnosticsEnabled !== false;losslessTracingToggle.checked = stored.losslessTrace === true;// Lossless recording only means something when tracing is on; mirror the// disabled state so the disclosure reads honestly.@@ -1494,6 +1496,14 @@ losslessTracingToggle.addEventListener('change', async () => {await chrome.storage.local.set({ losslessTrace: losslessTracingToggle.checked }).catch(() => {});});+feedbackDiagnosticsToggle?.addEventListener('change', async () => {+ await chrome.storage.local.set({ feedbackDiagnosticsEnabled: feedbackDiagnosticsToggle.checked });+ if (!feedbackDiagnosticsToggle.checked) {+ const response = await chrome.runtime.sendMessage({ target: 'background', action: 'feedback_clear_diagnostics' });+ if (!response?.ok) console.error('[feedback] Could not clear local diagnostics:', response?.error);+ }+});+costSessionLimitInput?.addEventListener('change', async () => {const value = normalizeCostAmount(costSessionLimitInput.value);costSessionLimitInput.value = value.toFixed(2);diff --git a/src/chrome/src/ui/sidepanel.html b/src/chrome/src/ui/sidepanel.htmlindex c6b8927f3..ea2cb0263 100644--- a/src/chrome/src/ui/sidepanel.html+++ b/src/chrome/src/ui/sidepanel.html@@ -11,6 +11,7 @@<script src="theme-bootstrap.js"></script><link rel="stylesheet" href="../../styles/sidepanel.css"><link rel="stylesheet" href="offline-rag-readiness.css">+ <link rel="stylesheet" href="feedback-consent.css"><link rel="stylesheet" href="../../vendor/katex/katex.min.css"><!-- KaTeX is loaded as classic scripts (not modules). They assign towindow.katex and window.renderMathInElement so formatMarkdown candiff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex b579d87e9..fa4c0711d 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -71,6 +71,8 @@ import {normalizeState as normalizeStoreReviewState,} from './store-review-prompt.js';import { providerIconUrl } from './provider-icons.js';+import { getFeedbackCopy } from './feedback-copy.js';+import { requestFeedbackConsent, submitFeedbackWithTrace } from './feedback-consent.js';import { parseWatchSlashCommand, WATCH_COMMAND_USAGE } from './watch-command.js';import { createSidePanelWindowScope } from './sidepanel-window-scope.js';import { visionProviderKind } from '../providers/vision-capabilities.js';@@ -1798,6 +1800,8 @@ function getExtensionStoreKey() {let storeReviewState = normalizeStoreReviewState(null);let storeReviewSelectedRating = null;+let storeReviewTraceSource = Promise.resolve(null);+let storeReviewSending = false;async function loadStoreReviewState() {const stored = await chrome.storage.local.get(STORE_REVIEW_STORAGE_KEY);@@ -1831,6 +1835,10 @@ function setStoreReviewStarPreview(rating) {async function openStoreReviewPrompt() {if (!storeReviewEl || isProcessing) return;+ // Freeze the session before tabs or conversations can change beneath the prompt.+ const sourceTabId = currentTabId;+ storeReviewTraceSource = sourceTabId == null ? Promise.resolve(null)+ : sendToBackground('export_traces', { tabId: sourceTabId, full: true }).catch(() => null);storeReviewSelectedRating = null;if (storeReviewFeedbackEl) storeReviewFeedbackEl.value = '';setStoreReviewStarPreview(null);@@ -1876,15 +1884,54 @@ async function handleStoreReviewOpenStore() {}async function handleStoreReviewSendFeedback() {+ if (storeReviewSending) return;+ storeReviewSending = true;const rating = storeReviewSelectedRating || storeReviewState.rating || 3;const comment = storeReviewFeedbackEl?.value || '';+ const copy = getFeedbackCopy(getLocale());+ const button = document.getElementById('store-review-send-feedback');+ const previousLabel = button?.textContent;+ if (button) { button.disabled = true; button.textContent = copy.preparing; }try {- chrome.tabs.create({ url: buildFeedbackUrl({ rating, comment }) });- } catch { /* ignore */ }- const next = markFeedbackSubmitted(storeReviewState);- await saveStoreReviewState(next);- showStoreReviewStep('thanks');- setTimeout(() => hideStoreReviewPrompt(), 2500);+ const { stageFeedbackTrace, deleteFeedbackDraft } = await import('../feedback-store.js');+ const source = await storeReviewTraceSource;+ const completed = await submitFeedbackWithTrace({+ rating, comment, copy,+ prepare: async () => {+ if (!source?.sessionId) return null;+ const flushed = await sendToBackground('feedback_flush');+ if (!flushed?.ok) throw new Error(flushed?.error || 'Trace flush failed.');+ const [store, { prepareFeedbackTrace }] = await Promise.all([+ import('../trace/recorder.js'), import('../trace/feedback-export.js'),+ ]);+ return prepareFeedbackTrace(store, source.sessionId, chrome.runtime.getManifest().version || '');+ },+ stage: prepared => stageFeedbackTrace({ ...prepared, copy }),+ discard: deleteFeedbackDraft,+ consent: (prepared, staged) => requestFeedbackConsent(prepared, copy, () => chrome.tabs.create({+ url: chrome.runtime.getURL(`src/ui/feedback-trace-preview.html?id=${encodeURIComponent(staged.id)}`),+ })),+ open: async params => {+ if (!params.includeTrace) {+ await chrome.tabs.create({ url: buildFeedbackUrl(params) });+ return;+ }+ const result = await sendToBackground('feedback_open', params);+ if (!result?.ok) throw new Error(result?.error || 'Could not open feedback.');+ },+ });+ if (!completed) return;+ await saveStoreReviewState(markFeedbackSubmitted(storeReviewState));+ showStoreReviewStep('thanks');+ const thanks = document.querySelector('#store-review-step-thanks .store-review-body');+ if (thanks) thanks.textContent = copy.draftReady;+ setTimeout(() => hideStoreReviewPrompt(), 2500);+ } catch (error) {+ showComposerToast(error?.message || String(error));+ } finally {+ storeReviewSending = false;+ if (button) { button.disabled = false; button.textContent = previousLabel; }+ }}function initStoreReviewPrompt() {diff --git a/src/chrome/src/ui/store-review-prompt.js b/src/chrome/src/ui/store-review-prompt.jsindex 0356ddafc..1c52388bf 100644--- a/src/chrome/src/ui/store-review-prompt.js+++ b/src/chrome/src/ui/store-review-prompt.js@@ -110,16 +110,21 @@ export function getStoreUrl(browserKey = 'chrome') {return STORE_URLS[browserKey] || STORE_URLS.chrome;}-export function buildFeedbackUrl({ rating, comment = '' } = {}) {- const title = encodeURIComponent(`WebBrain feedback (${rating}/5)`);+export function buildFeedbackBody({ rating, comment = '', traceNote = '' } = {}) {const bodyParts = [`**Rating:** ${rating}/5`,'',String(comment || '').trim() || '_No additional comments provided._',+ ...(traceNote ? ['', `**Trace:** ${String(traceNote)}`] : []),'','---','_Submitted from the WebBrain side panel feedback prompt._',];- const body = encodeURIComponent(bodyParts.join('\n'));+ return bodyParts.join('\n');+}++export function buildFeedbackUrl({ rating, comment = '', traceNote = '' } = {}) {+ const title = encodeURIComponent(`WebBrain feedback (${rating}/5)`);+ const body = encodeURIComponent(buildFeedbackBody({ rating, comment, traceNote }));return `${FEEDBACK_ISSUES_URL}?title=${title}&body=${body}`;}diff --git a/src/firefox/src/agent/trace-export.js b/src/firefox/src/agent/trace-export.jsindex 246beee2f..5a93b28eb 100644--- a/src/firefox/src/agent/trace-export.js+++ b/src/firefox/src/agent/trace-export.js@@ -20,6 +20,7 @@*/import { isKnownKind } from '../trace/event-model.js';+import { isErrorCode } from '../trace/error-codes.js';const ARGS_LIMIT = 300;const RESULT_LIMIT = 600;@@ -61,15 +62,40 @@ function redactExportValue(value, key = '') {return Object.fromEntries(Object.entries(value).map(([childKey, item]) => [childKey, redactExportValue(item, childKey)]));}-export function sanitizeTraceExport(payload) {- if (payload?.run?.lossless === true) return redactExportValue(payload);+const DIAGNOSTIC_CODE_KINDS = new Set(['error', 'turn_start', 'turn_end', 'step_start', 'step_end']);++function restoreDiagnosticCodes(entry, redacted) {+ if (!Array.isArray(entry?.events) || !Array.isArray(redacted?.events)) return;+ entry.events.forEach((event, index) => {+ const data = redacted.events[index]?.data;+ if (!data || typeof data !== 'object') return;+ // Only catalog codes in recorder metadata are public diagnostics. A code+ // in tool arguments/results or conversation content remains a credential.+ if (DIAGNOSTIC_CODE_KINDS.has(event.kind) && isErrorCode(event.data?.code)) data.code = event.data.code;+ if (event.kind === 'note' && data.extra && isErrorCode(event.data?.extra?.code)) data.extra.code = event.data.extra.code;+ });+}++function redactTraceExport(payload) {+ const redacted = redactExportValue(payload);+ restoreDiagnosticCodes(payload, redacted);+ if (Array.isArray(payload?.runs) && Array.isArray(redacted?.runs)) {+ payload.runs.forEach((entry, index) => restoreDiagnosticCodes(entry, redacted.runs[index]));+ }+ return redacted;+}++export function sanitizeTraceExport(payload, { allRuns = false } = {}) {+ // Feedback can include legacy rows that predate the lossless marker.+ if (allRuns) return redactTraceExport(payload);+ if (payload?.run?.lossless === true) return redactTraceExport(payload);if (!Array.isArray(payload?.runs)) return payload;let changed = false;const runs = payload.runs.map((entry) => {if (entry?.run?.lossless !== true) return entry;changed = true;- return redactExportValue(entry);+ return redactTraceExport(entry);});return changed ? { ...payload, runs } : payload;diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex 41eaa62fa..41712e4db 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -1,6 +1,8 @@import { resolveDecisionConfig, listDecisionModels } from './agent/decision-config.js';import { probeDecisionVision } from './agent/decision-vision-probe.js';import { installSafeSocialBackground } from './safesocial/background.js';+import { createFeedbackHandoff } from './feedback-handoff.js';+const feedbackHandoff = createFeedbackHandoff(browser);import { createSafeSocialHost } from './safesocial/host.js';import { firefoxBidi } from './bidi/client.js';import { ProviderManager } from './providers/manager.js';@@ -2480,6 +2482,7 @@ browser.runtime.onMessage.addListener((msg, sender) => {});async function handleMessage(msg, sender) {+ if (String(msg.action || '').startsWith('feedback_')) return feedbackHandoff.handle(msg, sender);if (msg.action === 'chat_steer') {// Content scripts must never turn page text into a trusted human correction.if (sender?.url?.split(/[?#]/)[0] !== browser.runtime.getURL('src/ui/sidepanel.html')) {diff --git a/src/firefox/src/config-transfer.js b/src/firefox/src/config-transfer.jsindex 7437499e5..d621f2731 100644--- a/src/firefox/src/config-transfer.js+++ b/src/firefox/src/config-transfer.js@@ -54,6 +54,7 @@ export const DEFAULT_CONFIG_SETTINGS = Object.freeze({completionConfetti: true,completionFlashTab: true,tracingEnabled: false,+ feedbackDiagnosticsEnabled: true,strictSecretMode: false,agentAllowLocalNetwork: false,scheduledTasksEnabled: true,@@ -136,6 +137,7 @@ const BOOLEAN_KEYS = new Set(['completionConfetti','completionFlashTab','tracingEnabled',+ 'feedbackDiagnosticsEnabled','strictSecretMode','agentAllowLocalNetwork','scheduledTasksEnabled',diff --git a/src/firefox/src/content/feedback-attachment.js b/src/firefox/src/content/feedback-attachment.jsnew file mode 100644index 000000000..ed6c42fde--- /dev/null+++ b/src/firefox/src/content/feedback-attachment.js@@ -0,0 +1,137 @@+(() => {+ if (globalThis.__webbrainFeedbackAttachment) return;+ globalThis.__webbrainFeedbackAttachment = true;+ const api = typeof browser !== 'undefined' ? browser : chrome;+ const destination = () => location.origin === 'https://github.com'+ && location.pathname === '/webbrain-one/webbrain/issues/new';+ if (!destination()) return;+ let draft, busy = false, banner, message, retryButton, downloadButton;+ const send = async (action, extra = {}) => {+ const result = await api.runtime.sendMessage({ target: 'background', action, id: draft?.id, token: draft?.token, ...extra });+ if (!result?.ok) throw new Error(result?.error || 'Feedback handoff failed.');+ return result;+ };+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));+ function editor() {+ const scope = document.querySelector('main') || document.body;+ return scope.querySelector('textarea[name="issue[body]"], textarea#issue_body')+ || [...scope.querySelectorAll('textarea')].find(input => !input.disabled && !input.readOnly);+ }+ function fileInput(input) {+ if (!input) return null;+ for (const scope of [input.closest('file-attachment'), input.closest('form'), document.querySelector('main')]) {+ if (!scope) continue;+ const candidates = [...scope.querySelectorAll('input[type="file"]')].filter(field => !field.disabled);+ if (candidates.length === 1) return candidates[0];+ }+ return null;+ }+ function attached(input) {+ // An arbitrary link or the filename by itself is not upload evidence.+ return [...String(input?.value || '').matchAll(/\[([^\]]+)\]\((https:\/\/[^\s)]+)\)/g)].some(match => {+ try {+ const url = new URL(match[2]);+ return match[1] === draft.filename && url.origin === 'https://github.com'+ && (url.pathname.startsWith('/user-attachments/files/') || url.pathname.startsWith('/files/'));+ } catch { return false; }+ });+ }+ function show(text, failed = false) {+ message.textContent = text;+ retryButton.hidden = !failed || !draft.includeTrace;+ downloadButton.hidden = !failed || !draft.includeTrace;+ }+ function createBanner() {+ banner = document.createElement('aside');+ banner.setAttribute('role', 'status');+ banner.style.cssText = 'position:fixed;bottom:20px;right:20px;z-index:2147483647;max-width:420px;padding:16px;border:1px solid #8b949e;border-radius:8px;background:#fff;color:#24292f;box-shadow:0 4px 24px #0003;font:14px/1.5 system-ui';+ message = document.createElement('p'); message.style.margin = '0 0 8px';+ retryButton = document.createElement('button'); retryButton.type = 'button';+ retryButton.textContent = draft.copy.retry || 'Retry attachment'; retryButton.hidden = true;+ retryButton.addEventListener('click', async () => {+ if (busy) return;+ retryButton.disabled = true;+ try { await send('feedback_retry'); await upload(); }+ catch (error) { show(error.message, true); }+ finally { retryButton.disabled = false; }+ });+ downloadButton = document.createElement('button'); downloadButton.type = 'button';+ downloadButton.textContent = draft.copy.download || 'Download trace'; downloadButton.hidden = true;+ downloadButton.addEventListener('click', () => void send('feedback_preview').catch(error => show(error.message, true)));+ const close = document.createElement('button'); close.type = 'button'; close.textContent = '×';+ close.setAttribute('aria-label', draft.copy.close || 'Close');+ close.style.cssText = 'float:right;margin-left:8px'; close.addEventListener('click', () => banner.remove());+ banner.append(close, message, retryButton, downloadButton); document.body.append(banner);+ }+ async function waitForEditor() {+ for (let attempt = 0; attempt < 120 && destination(); attempt++) {+ const input = editor();+ if (input) return input;+ await sleep(250);+ }+ throw new Error(draft.copy.failed || 'The GitHub editor is not available.');+ }+ async function complete() {+ await send('feedback_result', { success: true });+ show(draft.copy.ready || 'Trace attached. Review and submit your feedback on GitHub.');+ }+ async function upload() {+ if (busy || !destination()) return;+ busy = true;+ try {+ const input = await waitForEditor();+ if (attached(input)) { await complete(); return; }+ show(draft.copy.uploading || 'Attaching your trace. Please wait before submitting the issue.');+ const chunks = [];+ for (let offset = 0; offset < draft.size; offset += draft.chunkBytes) {+ if (!destination()) throw new Error('The feedback destination changed.');+ const response = await send('feedback_chunk', { offset });+ const binary = atob(response.base64);+ chunks.push(Uint8Array.from(binary, character => character.charCodeAt(0)));+ }+ let target;+ for (let attempt = 0; attempt < 80 && destination(); attempt++) {+ target = fileInput(editor());+ if (target) break;+ await sleep(250);+ }+ if (!target || !destination()) throw new Error(draft.copy.failed || 'The GitHub upload control is not available.');+ await send('feedback_upload_started');+ const transfer = new DataTransfer();+ transfer.items.add(new File(chunks, draft.filename, { type: draft.mimeType || 'application/json' }));+ target.files = transfer.files;+ target.dispatchEvent(new Event('input', { bubbles: true }));+ target.dispatchEvent(new Event('change', { bubbles: true }));+ for (let attempt = 0; attempt < 240 && destination(); attempt++) {+ if (attached(editor())) { await complete(); return; }+ await sleep(250);+ }+ throw new Error(draft.copy.failed || 'The trace attachment could not be confirmed.');+ } catch (error) {+ await send('feedback_result', { success: false }).catch(() => {});+ show(draft.copy.failed || error.message, true);+ } finally { busy = false; }+ }+ void (async () => {+ draft = await send('feedback_claim');+ draft.copy ||= {};+ createBanner();+ const input = await waitForEditor();+ // React listens to native input events. Never replace text the user edited.+ if (!input.value || input.value.trim() === draft.initialBody.trim()) {+ const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set;+ setter.call(input, draft.body);+ input.dispatchEvent(new Event('input', { bubbles: true }));+ input.dispatchEvent(new Event('change', { bubbles: true }));+ }+ if (!draft.includeTrace) {+ await send('feedback_result', { success: true });+ show(draft.copy.draftReady || 'Review and submit your feedback on GitHub.');+ } else if (attached(input)) await complete();+ else if (draft.status === 'uploading' || draft.status === 'failed') show(draft.copy.failed || 'Check the draft, then retry the attachment if needed.', true);+ else await upload();+ })().catch(error => {+ if (banner) show(draft?.copy?.failed || error.message, true);+ else globalThis.__webbrainFeedbackAttachment = false;+ });+})();diff --git a/src/firefox/src/feedback-handoff.js b/src/firefox/src/feedback-handoff.jsnew file mode 100644index 000000000..ad6b55bf5--- /dev/null+++ b/src/firefox/src/feedback-handoff.js@@ -0,0 +1,163 @@+import {+ getFeedbackDraft, listFeedbackDrafts, putFeedbackDraft, updateFeedbackDraft, deleteFeedbackDraft,+ sweepFeedbackDrafts, FEEDBACK_TTL_MS, FEEDBACK_CHUNK_BYTES,+} from './feedback-store.js';+import { buildFeedbackBody, FEEDBACK_ISSUES_URL } from './ui/store-review-prompt.js';+import { flushPendingWrites, pruneFeedbackDiagnostics } from './trace/recorder.js';++export function isFeedbackDestination(url) {+ try {+ const parsed = new URL(url);+ return parsed.origin === 'https://github.com'+ && parsed.pathname === '/webbrain-one/webbrain/issues/new';+ } catch { return false; }+}++export function mayReadFeedbackDraft(draft, sender, tabUrl, now = Date.now()) {+ return Boolean(draft && draft.authorized && draft.expiresAt > now+ && sender?.frameId === 0 && sender.tab?.id === draft.destinationTabId+ && isFeedbackDestination(sender.url) && isFeedbackDestination(tabUrl));+}++export function createFeedbackHandoff(api) {+ const inflight = new Set();+ const panelUrl = api.runtime.getURL('src/ui/sidepanel.html');+ const settingsUrl = api.runtime.getURL('src/ui/settings.html');+ const isPanel = sender => sender?.id === api.runtime.id+ && sender.url?.split(/[?#]/)[0] === panelUrl;+ async function cleanup() {+ const settings = await api.storage.local.get('feedbackDiagnosticsEnabled');+ await Promise.all([+ sweepFeedbackDrafts(),+ pruneFeedbackDiagnostics({ clear: settings.feedbackDiagnosticsEnabled === false }),+ ]);+ }+ const storeReady = cleanup().catch(() => {});++ async function inject(tabId) {+ await storeReady;+ if (inflight.has(tabId)) return;+ const tab = await api.tabs.get(tabId);+ if (!isFeedbackDestination(tab.url)) return;+ const draft = (await listFeedbackDrafts()).find(row => row.destinationTabId === tabId && row.authorized && row.expiresAt > Date.now());+ if (!draft) return;+ inflight.add(tabId);+ try {+ if (api.scripting?.executeScript) await api.scripting.executeScript({+ target: { tabId, frameIds: [0] }, files: ['src/content/feedback-attachment.js'],+ });+ else await api.tabs.executeScript(tabId, { file: 'src/content/feedback-attachment.js', frameId: 0 });+ } finally { inflight.delete(tabId); }+ }++ api.tabs.onUpdated.addListener((tabId, change) => {+ if (change.status === 'complete') void inject(tabId).catch(() => {});+ });+ api.tabs.onRemoved.addListener(tabId => { void sweepFeedbackDrafts({ tabId }).catch(() => {}); });+ api.alarms.onAlarm.addListener(alarm => {+ if (alarm.name === 'feedback-draft-cleanup') void cleanup().catch(() => {});+ });+ api.storage.onChanged?.addListener((changes, area) => {+ if (area === 'local' && changes.feedbackDiagnosticsEnabled?.newValue === false) {+ void pruneFeedbackDiagnostics({ clear: true }).catch(() => {});+ }+ });+ api.alarms.create('feedback-draft-cleanup', { periodInMinutes: 5 });+ // A worker may have restarted after the document loaded, without an update event.+ void storeReady.then(async () => {+ for (const draft of await listFeedbackDrafts()) {+ if (draft.destinationTabId !== null) void inject(draft.destinationTabId).catch(() => {});+ }+ }).catch(() => {});++ return {+ async handle(msg, sender) {+ await storeReady;+ if (msg.action === 'feedback_flush') {+ if (!isPanel(sender)) throw new Error('Chat panel only.');+ await flushPendingWrites();+ return { ok: true };+ }+ if (msg.action === 'feedback_clear_diagnostics') {+ if (sender?.id !== api.runtime.id || sender.url?.split(/[?#]/)[0] !== settingsUrl) throw new Error('Settings only.');+ await pruneFeedbackDiagnostics({ clear: true });+ return { ok: true };+ }+ if (msg.action === 'feedback_open') {+ if (!isPanel(sender)) throw new Error('Feedback can only be sent from the chat panel.');+ const rating = Math.max(1, Math.min(5, Math.round(Number(msg.rating) || 3)));+ const body = buildFeedbackBody({ rating, comment: msg.comment, traceNote: msg.traceNote });+ let draft = msg.includeTrace ? await getFeedbackDraft(String(msg.id || '')) : null;+ if (msg.includeTrace && (!draft?.blob || draft.expiresAt <= Date.now()+ || draft.status !== 'prepared')) throw new Error('Prepare and review the trace again before uploading.');+ // The dedicated action from the consent button authorizes these staged,+ // immutable bytes; page content cannot call this extension-page route.+ draft = draft || {+ id: crypto.randomUUID(), token: crypto.randomUUID(),+ createdAt: Date.now(), expiresAt: Date.now() + FEEDBACK_TTL_MS,+ };+ draft = { ...draft, body, initialBody: `**Rating:** ${rating}/5`,+ authorized: true, consentAt: msg.includeTrace ? Date.now() : null,+ status: 'pending', copy: msg.copy || {}, includeTrace: msg.includeTrace === true };+ if (encodeURIComponent(body).length < 6000) draft.initialBody = body;+ let tab;+ try {+ tab = await api.tabs.create({ url: 'about:blank' });+ draft.destinationTabId = tab.id;+ await putFeedbackDraft(draft);+ const url = new URL(FEEDBACK_ISSUES_URL);+ url.searchParams.set('title', `WebBrain feedback (${rating}/5)`);+ url.searchParams.set('body', draft.initialBody);+ await api.tabs.update(tab.id, { url: url.href });+ return { ok: true, tabId: tab.id };+ } catch (error) {+ await deleteFeedbackDraft(draft.id);+ if (tab) await api.tabs.remove(tab.id).catch(() => {});+ throw error;+ }+ }+ const draft = msg.action === 'feedback_claim'+ ? (await listFeedbackDrafts()).find(row => row.destinationTabId === sender?.tab?.id)+ : await getFeedbackDraft(String(msg.id || ''));+ const tab = sender?.tab ? await api.tabs.get(sender.tab.id) : null;+ if (sender?.id !== api.runtime.id || !mayReadFeedbackDraft(draft, sender, tab?.url)+ || (msg.action !== 'feedback_claim' && msg.token !== draft.token)) throw new Error('Unauthorized feedback handoff.');+ if (msg.action === 'feedback_claim') return {+ ok: true, id: draft.id, token: draft.token, body: draft.body, initialBody: draft.initialBody,+ filename: draft.filename, size: draft.blob?.size || 0, mimeType: draft.blob?.type,+ status: draft.status, includeTrace: draft.includeTrace, chunkBytes: FEEDBACK_CHUNK_BYTES,+ copy: draft.copy || {},+ };+ if (msg.action === 'feedback_preview') {+ if (!draft.includeTrace) throw new Error('No trace was selected.');+ await api.tabs.create({ url: api.runtime.getURL(`src/ui/feedback-trace-preview.html?id=${encodeURIComponent(draft.id)}`) });+ return { ok: true };+ }+ if (msg.action === 'feedback_chunk') {+ if (!draft.includeTrace || !Number.isSafeInteger(msg.offset) || msg.offset < 0 || msg.offset >= draft.blob.size) throw new Error('Invalid feedback chunk.');+ const bytes = new Uint8Array(await draft.blob.slice(msg.offset, msg.offset + FEEDBACK_CHUNK_BYTES).arrayBuffer());+ let binary = '';+ for (let offset = 0; offset < bytes.length; offset += 8192) binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));+ return { ok: true, base64: btoa(binary) };+ }+ if (msg.action === 'feedback_upload_started') {+ await updateFeedbackDraft(draft.id, current => {+ if (!current?.includeTrace || !['pending', 'failed'].includes(current.status)) throw new Error('Attachment already dispatched.');+ return { ...current, status: 'uploading' };+ });+ return { ok: true };+ }+ if (msg.action === 'feedback_retry') {+ if (!draft.includeTrace || !['failed', 'uploading'].includes(draft.status)) throw new Error('No failed attachment to retry.');+ await putFeedbackDraft({ ...draft, status: 'failed' });+ return { ok: true };+ }+ if (msg.action === 'feedback_result') {+ if (msg.success === true) await deleteFeedbackDraft(draft.id);+ else await putFeedbackDraft({ ...draft, status: 'failed' });+ return { ok: true };+ }+ throw new Error('Unknown feedback action.');+ },+ };+}diff --git a/src/firefox/src/feedback-store.js b/src/firefox/src/feedback-store.jsnew file mode 100644index 000000000..e3762e5c9--- /dev/null+++ b/src/firefox/src/feedback-store.js@@ -0,0 +1,65 @@+export const FEEDBACK_TTL_MS = 60 * 60 * 1000;+export const FEEDBACK_CHUNK_BYTES = 128 * 1024;+let database;++function openDB() {+ if (!database) database = new Promise((resolve, reject) => {+ const request = indexedDB.open('webbrain_feedback', 1);+ request.onupgradeneeded = () => request.result.createObjectStore('drafts', { keyPath: 'id' });+ request.onsuccess = () => resolve(request.result);+ request.onerror = () => { database = null; reject(request.error); };+ });+ return database;+}++async function operation(mode, action) {+ const db = await openDB();+ return new Promise((resolve, reject) => {+ const transaction = db.transaction('drafts', mode);+ const request = action(transaction.objectStore('drafts'));+ transaction.oncomplete = () => resolve(request?.result);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback storage aborted.'));+ });+}++export const getFeedbackDraft = id => operation('readonly', store => store.get(id));+export const listFeedbackDrafts = () => operation('readonly', store => store.getAll());+export const putFeedbackDraft = draft => operation('readwrite', store => store.put(draft));+export const deleteFeedbackDraft = id => operation('readwrite', store => store.delete(id));++// A single transaction prevents two restarted/injected helpers from both+// dispatching the same attachment after reading a pending state.+export async function updateFeedbackDraft(id, update) {+ const db = await openDB();+ return new Promise((resolve, reject) => {+ const transaction = db.transaction('drafts', 'readwrite');+ const store = transaction.objectStore('drafts');+ const request = store.get(id);+ let updated;+ request.onsuccess = () => {+ try { updated = update(request.result); if (updated) store.put(updated); }+ catch (error) { reject(error); transaction.abort(); }+ };+ transaction.oncomplete = () => resolve(updated);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback update aborted.'));+ });+}++export async function stageFeedbackTrace(prepared) {+ const draft = {+ ...prepared, preview: undefined,+ id: crypto.randomUUID(), token: crypto.randomUUID(),+ createdAt: Date.now(), expiresAt: Date.now() + FEEDBACK_TTL_MS,+ authorized: false, status: 'prepared', destinationTabId: null,+ };+ await putFeedbackDraft(draft);+ return draft;+}++export async function sweepFeedbackDrafts({ now = Date.now(), tabId = null } = {}) {+ for (const draft of await listFeedbackDrafts()) {+ if (draft.expiresAt <= now || (tabId !== null && draft.destinationTabId === tabId)) await deleteFeedbackDraft(draft.id);+ }+}diff --git a/src/firefox/src/trace/feedback-export.js b/src/firefox/src/trace/feedback-export.jsnew file mode 100644index 000000000..b5e2ada1a--- /dev/null+++ b/src/firefox/src/trace/feedback-export.js@@ -0,0 +1,103 @@+import { exportRecordedSession } from './session-export.js';+import { sanitizeTraceExport } from '../agent/trace-export.js';+import { projectTraceEventData } from './privacy.js';+import { normalizeRuntimeTraceConfig } from './runtime-config.js';++export const FEEDBACK_ATTACHMENT_LIMIT = 20 * 1024 * 1024;++const DIAGNOSTIC_RUN_FIELDS = [+ 'runId', 'conversationId', 'parentRunId', 'parentSessionId', 'delegationDepth',+ 'startedAt', 'endedAt', 'durationMs', 'status', 'model', 'providerId', 'providerClass',+ 'webbrainVersion', 'traceFormatVersion', 'mode', 'stepCount', 'totalInputTokens',+ 'totalOutputTokens', 'totalCost', 'llmRequestCount', 'llmResponseCount', 'toolCallCount',+ 'visionSubCallCount', 'errorCount', 'retryCount', 'totalLlmLatencyMs', 'totalToolLatencyMs',+ 'feedbackOnly', 'feedbackHistoryOmitted', 'feedbackEventsOmitted',+];++export function diagnosticFeedbackPayload(payload) {+ return {+ ...payload,+ runs: payload.runs.map(({ run, events }) => ({+ // Legacy rows can have unknown content fields. A diagnostic fallback+ // must not copy those fields, including unknown event-envelope fields.+ run: { ...Object.fromEntries(DIAGNOSTIC_RUN_FIELDS.filter(key => run[key] !== undefined).map(key => [key, run[key]])),+ runtimeConfig: normalizeRuntimeTraceConfig(run.runtimeConfig), lossless: false },+ events: events.map(event => ({ runId: event.runId, seq: event.seq, ts: event.ts, kind: event.kind, data: {+ ...projectTraceEventData(event.kind, event.data),+ ...(event.kind === 'tool' && !event.data?.result ? {+ resultStatus: event.data?.resultStatus || 'unknown',+ ...(event.data?.resultErrorCode || event.data?.errorCode ? { resultErrorCode: event.data.resultErrorCode || event.data.errorCode } : {}),+ } : {}),+ } })),+ })),+ feedbackOmissions: [...(payload.feedbackOmissions || []), 'Full trace exceeds the attachment size limit; diagnostic metadata only.'],+ };+}++export async function prepareFeedbackTrace(store, sessionId, version = '', {+ limit = FEEDBACK_ATTACHMENT_LIMIT,+ compress = async blob => typeof CompressionStream === 'function'+ ? new Response(blob.stream().pipeThrough(new CompressionStream('gzip'))).blob() : null,+} = {}) {+ if (!sessionId) return null;+ const exported = await exportRecordedSession(store, sessionId, version);+ if (!exported.turnCount) return null;+ let payload = sanitizeTraceExport(JSON.parse(exported.json), { allRuns: true });+ const omissions = [];+ if (exported.recordingTruncated) omissions.push('Some content was omitted at recording time.');+ if (payload.runs.some(entry => entry.run.feedbackHistoryOmitted || entry.run.feedbackEventsOmitted)) {+ omissions.push('Automatic diagnostic history is bounded; older runs or events may be absent.');+ }+ payload.feedbackOmissions = omissions;+ const originalBlob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ let blob = originalBlob;+ let filename = `webbrain-feedback-${Date.now()}.json`;+ if (blob.size >= limit) {+ let compressed;+ try { compressed = await compress(blob); } catch { /* diagnostic fallback below */ }+ if (compressed && compressed.size < limit) {+ blob = new Blob([compressed], { type: 'application/gzip' });+ filename += '.gz';+ } else {+ payload = diagnosticFeedbackPayload(payload);+ // Bound the fallback as well; retain a visible omission marker.+ const budget = Math.min(limit / 2, 256 * 1024);+ let used = 0;+ payload.runs = payload.runs.slice().reverse().map(entry => {+ const events = [];+ for (const event of entry.events.slice().reverse()) {+ const size = new TextEncoder().encode(JSON.stringify(event)).length;+ if (used + size > budget) { entry.run.feedbackEventsOmitted = true; continue; }+ used += size;+ events.unshift(event);+ }+ return { run: entry.run, events };+ }).reverse();+ blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ // Whitespace and run headers also count toward GitHub's file limit.+ while (blob.size >= limit) {+ const entry = payload.runs.find(item => item.events.length);+ if (entry) { entry.events.shift(); entry.run.feedbackEventsOmitted = true; }+ else if (payload.runs.length > 1) {+ payload.runs.shift();+ if (!payload.feedbackOmissions.includes('Older runs omitted to fit the attachment.')) payload.feedbackOmissions.push('Older runs omitted to fit the attachment.');+ } else break;+ blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });+ }+ filename = filename.replace(/\.json$/, '-diagnostics.json');+ if (blob.size >= limit) throw new Error('Diagnostic attachment exceeds the size limit.');+ }+ }+ const screenshotCount = payload.runs.reduce((sum, entry) => sum + entry.events.filter(event =>+ event.kind === 'screenshot' && (event.data?.screenshot_base64 || event.data?.screenshot_dataUrl)).length, 0);+ const traceType = screenshotCount > 0 || payload.runs.some(entry => entry.run.lossless === true+ || ['userMessage', 'finalContent', 'tabUrl', 'tabTitle'].some(key => entry.run[key])+ || entry.run.attachments?.length+ || entry.events.some(event => ['messages', 'result', 'args', 'content', 'text', 'message', 'reasoning', 'tools'].some(key => event.data?.[key])))+ ? 'full' : 'diagnostic';+ return {+ blob, originalBlob, filename, sessionId, traceType,+ runCount: payload.runs.length, screenshotCount,+ omissions: payload.feedbackOmissions,+ };+}diff --git a/src/firefox/src/trace/feedback-policy.js b/src/firefox/src/trace/feedback-policy.jsnew file mode 100644index 000000000..23a14f448--- /dev/null+++ b/src/firefox/src/trace/feedback-policy.js@@ -0,0 +1,33 @@+export const FEEDBACK_DIAGNOSTICS_KEY = 'feedbackDiagnosticsEnabled';+export const FEEDBACK_HISTORY_RUNS = 10;+export const FEEDBACK_HISTORY_AGE_MS = 7 * 24 * 60 * 60 * 1000;+export const FEEDBACK_HISTORY_BYTES = 2 * 1024 * 1024;+export const FEEDBACK_RUN_BYTES = 128 * 1024;++// Automatic diagnostics must never inherit a stale lossless preference.+export function feedbackRecordingPolicy(settings, forced = false) {+ const feedbackOnly = !forced && settings.tracingEnabled !== true+ && settings[FEEDBACK_DIAGNOSTICS_KEY] !== false;+ return {+ enabled: forced || settings.tracingEnabled === true || feedbackOnly,+ feedbackOnly,+ lossless: !feedbackOnly && settings.losslessTrace === true,+ };+}++export function feedbackRunsToEvict(runs, now = Date.now()) {+ const automatic = runs.filter(run => run.feedbackOnly === true);+ const completed = automatic.filter(run => run.status !== 'running')+ .sort((a, b) => (b.startedAt || 0) - (a.startedAt || 0));+ let bytes = automatic.filter(run => run.status === 'running')+ .reduce((sum, run) => sum + (Number(run.feedbackBytes) || 0), 0);+ let kept = 0;+ return completed.filter(run => {+ const size = Number(run.feedbackBytes) || 0;+ if (now - (run.startedAt || 0) > FEEDBACK_HISTORY_AGE_MS+ || kept >= FEEDBACK_HISTORY_RUNS || bytes + size > FEEDBACK_HISTORY_BYTES) return true;+ kept += 1;+ bytes += size;+ return false;+ }).map(run => run.runId);+}diff --git a/src/firefox/src/trace/recorder.js b/src/firefox/src/trace/recorder.jsindex 740a96136..0c54ac9c6 100644--- a/src/firefox/src/trace/recorder.js+++ b/src/firefox/src/trace/recorder.js@@ -14,6 +14,7 @@ import {import { createTraceStats, addTraceEvent, aggregateTraceRuns } from './stats.js';import { projectTraceEventData, projectTraceRun } from './privacy.js';import { toolOutcome } from './tool-outcome.js';+import { feedbackRecordingPolicy, feedbackRunsToEvict, FEEDBACK_RUN_BYTES, FEEDBACK_HISTORY_BYTES } from './feedback-policy.js';/*** Trace recorder — writes per-run traces (LLM requests/responses, tool calls,@@ -25,9 +26,10 @@ import { toolOutcome } from './tool-outcome.js';* - shots keyPath=[runId, seq] // screenshot Blobs** All writes are fire-and-forget. Recording is gated on the `tracingEnabled`- * setting. When disabled, every call is a cheap no-op.+ * setting, explicit forced runs, or bounded automatic feedback diagnostics.*/+const traceStorage = () => (typeof browser !== 'undefined' ? browser : chrome).storage.local;const DB_NAME = 'webbrain_traces';const DB_VERSION = 2;@@ -96,23 +98,46 @@ function promisifyReq(req) {async function tracingEnabled() {try {if (typeof indexedDB === 'undefined') return false;- const storageApi = (typeof browser !== 'undefined' ? browser : chrome).storage.local;- const { tracingEnabled } = await storageApi.get(['tracingEnabled']);+ const { tracingEnabled } = await traceStorage().get(['tracingEnabled']);return tracingEnabled === true;} catch { return false; }}-// Opt-in lossless tier: same event pipeline, full request payloads instead of-// content-free provenance. Read once per run at startRun; never per event.-async function losslessTraceEnabled() {+async function isForcedTraceRun(runId) {+ if (!runId) return false;+ if (_runState.get(runId)?.feedbackOnly === true) {+ const settings = await traceStorage().get('feedbackDiagnosticsEnabled');+ return settings.feedbackDiagnosticsEnabled !== false;+ }+ if (_runState.get(runId)?.forced === true) return true;try {- if (typeof indexedDB === 'undefined') return false;- const storageApi = (typeof browser !== 'undefined' ? browser : chrome).storage.local;- const { losslessTrace } = await storageApi.get(['losslessTrace']);- return losslessTrace === true;+ const db = await openDB();+ const record = await promisifyReq(+ tx(db, ['runs'], 'readonly').objectStore('runs').get(runId),+ );+ if (record?.feedbackOnly === true) {+ const settings = await traceStorage().get('feedbackDiagnosticsEnabled');+ return settings.feedbackDiagnosticsEnabled !== false;+ }+ return record?.forced === true;} catch { return false; }}+async function tracingEnabledForRun(runId) {+ return (await tracingEnabled()) || (await isForcedTraceRun(runId));+}++// Restore per-run flags after SW eviction from the durable run record so the+// lossless tier decision survives a worker restart mid-run.+async function peekRunFlags(db, runId) {+ try {+ const record = await promisifyReq(+ tx(db, ['runs'], 'readonly').objectStore('runs').get(runId),+ );+ return { forced: record?.forced === true, feedbackOnly: record?.feedbackOnly === true, feedbackBytes: record?.feedbackBytes || 0, lossless: record?.lossless === true, losslessBytes: record?.losslessBytes || 0, losslessBytesEncoding: record?.losslessBytesEncoding || '' };+ } catch { return { forced: false, lossless: false, losslessBytes: 0 }; }+}+// ----- Per-run state (held in memory on the service worker) ------------------//// A run lives only as long as its processMessage() call. If the SW gets@@ -122,7 +147,7 @@ async function losslessTraceEnabled() {const _runState = new Map(); // runId -> { seq, model, providerId, ... }const _runWriteQueues = new Map(); // runId -> serialized event-write promise-// Bounded raw tool payloads live only for the active background lifetime. The+// Bounded raw tool payloads live only for the active worker lifetime. The// agent turns them into the existing value-free saved-workflow schema at// successful run completion; they never cross the default durable trace// boundary.@@ -161,17 +186,6 @@ async function _peekSeq(db, runId) {return result;}-// Restore per-run flags after worker eviction from the durable run record so-// the lossless tier decision survives a worker restart mid-run.-async function peekRunFlags(db, runId) {- try {- const record = await promisifyReq(- tx(db, ['runs'], 'readonly').objectStore('runs').get(runId),- );- return { lossless: record?.lossless === true, losslessBytes: record?.losslessBytes || 0, losslessBytesEncoding: record?.losslessBytesEncoding || '' };- } catch { return { lossless: false, losslessBytes: 0 }; }-}-const _runStateLoads = new Map();async function _ensureRunState(runId, db = null) {@@ -185,7 +199,7 @@ async function _ensureRunState(runId, db = null) {const resolvedDb = db || await openDB();const seq = await _peekSeq(resolvedDb, runId);const flags = await peekRunFlags(resolvedDb, runId);- const state = { seq, lossless: flags.lossless, losslessBytes: Number(flags.losslessBytes) || 0, losslessBytesEncoding: flags.losslessBytesEncoding };+ const state = { seq, forced: flags.forced, feedbackOnly: flags.feedbackOnly, feedbackBytes: flags.feedbackBytes, lossless: flags.lossless, losslessBytes: Number(flags.losslessBytes) || 0, losslessBytesEncoding: flags.losslessBytesEncoding };_runState.set(runId, state);return state;} catch { return null; }@@ -368,15 +382,19 @@ function normalizeTraceAttachments(attachments) {// ----- Public API -------------------------------------------------------------export async function startRun(meta) {- if (!(await tracingEnabled())) return null;+export async function startRun(meta = {}) {try {+ if (typeof indexedDB === 'undefined') return null;+ const settings = await traceStorage().get(['tracingEnabled', 'losslessTrace', 'feedbackDiagnosticsEnabled']);+ const policy = feedbackRecordingPolicy(settings, meta.force === true);+ if (!policy.enabled) return null;+ const forced = meta.force === true || policy.feedbackOnly;const db = await openDB();const runId = meta.runId || `run_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;const lineage = normalizeRunHeader(meta) || {};// Tier is decided once per run: explicit caller override wins, otherwise// the opt-in setting. Never forced for local runs by default.- const lossless = meta.lossless === true || await losslessTraceEnabled();+ const lossless = !policy.feedbackOnly && (meta.lossless === true || policy.lossless);const record = projectTraceRun({runId,// Stable per-conversation id so the Traces UI can group sibling runs@@ -405,6 +423,8 @@ export async function startRun(meta) {mode: meta.mode || 'act',attachments: normalizeTraceAttachments(meta.attachments),...(lossless ? { lossless: true, losslessBytes: 0, losslessBytesEncoding: 'utf8' } : {}),+ forced,+ ...(policy.feedbackOnly ? { feedbackOnly: true, feedbackHistoryOmitted: true, feedbackBytes: 0 } : {}),stepCount: 0,totalInputTokens: 0,totalOutputTokens: 0,@@ -418,8 +438,31 @@ export async function startRun(meta) {totalToolLatencyMs: 0,finalContent: null,}, { includeContent: lossless });- await promisifyReq(tx(db, ['runs']).objectStore('runs').put(record));- _runState.set(runId, { seq: 0, model: record.model, providerId: record.providerId, lossless, losslessBytes: 0, losslessBytesEncoding: lossless ? 'utf8' : '' });+ if (policy.feedbackOnly) {+ await pruneFeedbackDiagnostics();+ // Reserve room for final statistics and omission flags as well as events.+ record.feedbackBytes = utf8ByteLength(JSON.stringify(record)) + 1024;+ }+ if (policy.feedbackOnly) {+ const saved = await new Promise((resolve, reject) => {+ const transaction = tx(db, ['runs']);+ const store = transaction.objectStore('runs');+ const request = store.getAll();+ let inserted = false;+ request.onsuccess = () => {+ const total = request.result.filter(row => row.feedbackOnly)+ .reduce((sum, row) => sum + (Number(row.feedbackBytes) || 0), 0);+ if (record.feedbackBytes > FEEDBACK_RUN_BYTES+ || total + record.feedbackBytes > FEEDBACK_HISTORY_BYTES - 4096) return;+ store.put(record); inserted = true;+ };+ transaction.oncomplete = () => resolve(inserted);+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error);+ });+ if (!saved) return null;+ } else await promisifyReq(tx(db, ['runs']).objectStore('runs').put(record));+ _runState.set(runId, { seq: 0, model: record.model, providerId: record.providerId, forced, feedbackOnly: policy.feedbackOnly, feedbackBytes: record.feedbackBytes || 0, lossless, losslessBytes: 0, losslessBytesEncoding: lossless ? 'utf8' : '' });_workflowTraceCaptures.set(runId, {run: {runId,@@ -485,7 +528,7 @@ function _putAuxiliaryUsage(db, runId, event) {}async function _appendEventNow(runId, kind, data) {- if (!(await tracingEnabled())) return;+ if (!(await tracingEnabledForRun(runId))) return;try {const db = await openDB();const state = await _ensureRunState(runId, db);@@ -519,6 +562,9 @@ async function _appendEventNow(runId, kind, data) {console.warn('[trace] dropped invalid event:', kind);return null;}+ if (state?.feedbackOnly === true) {+ return await writeFeedbackEvent(db, runId, ev, state);+ }if (state?.lossless === true && (kind === 'llm_request' || kind === 'tool')) {if (losslessBudgetOmitted) {await promisifyReq(tx(db, ['events']).objectStore('events').put(ev));@@ -543,6 +589,58 @@ async function _appendEventNow(runId, kind, data) {}}+let _feedbackWriteQueue = Promise.resolve();++// Serialize the shared byte budget across concurrently running tabs.+function writeFeedbackEvent(db, runId, event, state) {+ const pending = _feedbackWriteQueue.catch(() => {}).then(async () => {+ const bytes = utf8ByteLength(JSON.stringify(event));+ return new Promise((resolve, reject) => {+ const transaction = tx(db, ['runs', 'events']);+ const store = transaction.objectStore('runs');+ // Read the budget and write the event in one transaction. Other+ // extension contexts can prune/start runs without invalidating a cache.+ const request = store.getAll();+ let saved = false;+ request.onsuccess = () => {+ const run = request.result.find(row => row.runId === runId);+ const total = request.result.filter(row => row.feedbackOnly)+ .reduce((sum, row) => sum + (Number(row.feedbackBytes) || 0), 0);+ if (!run?.feedbackOnly) return;+ // Reserve a little space for final statistics and omission flags.+ if ((run.feedbackBytes || 0) + bytes > FEEDBACK_RUN_BYTES+ || total + bytes > FEEDBACK_HISTORY_BYTES - 4096) {+ run.feedbackEventsOmitted = true;+ store.put(run);+ return;+ }+ run.feedbackBytes = (run.feedbackBytes || 0) + bytes;+ store.put(run);+ transaction.objectStore('events').put(event);+ saved = true;+ };+ transaction.oncomplete = () => {+ if (saved) state.feedbackBytes += bytes;+ resolve(saved ? event.seq : null);+ };+ transaction.onerror = () => reject(transaction.error);+ transaction.onabort = () => reject(transaction.error || new Error('Feedback diagnostic write aborted.'));+ });+ });+ _feedbackWriteQueue = pending;+ return pending;+}++export async function pruneFeedbackDiagnostics({ clear = false, now = Date.now() } = {}) {+ if (typeof indexedDB === 'undefined') return;+ const db = await openDB();+ const rows = await promisifyReq(tx(db, ['runs'], 'readonly').objectStore('runs').getAll());+ const ids = clear ? rows.filter(run => run.feedbackOnly === true).map(run => run.runId)+ : [...new Set([...feedbackRunsToEvict(rows, now), ...rows.filter(run => run.feedbackOnly === true+ && now - (run.startedAt || 0) > 7 * 24 * 60 * 60 * 1000).map(run => run.runId)])];+ for (const id of ids) { await deleteRun(id); if (clear) _runState.delete(id); }+}+// Retain the active run and evict completed lossless runs oldest first when// their aggregate recorded payload crosses the global budget. A cached running// total keeps under-budget writes free of any store-wide scan; the scan itself@@ -666,8 +764,9 @@ function _appendEvent(runId, kind, data) {export function recordLLMRequest(runId, step, payload, provenanceInput = null) {// Lossless tier (opt-in): persist the request's full message/tool shape for- // deep debugging and request reconstruction. Clamp oversized requests so- // one request cannot exhaust IndexedDB.+ // deep debugging and request reconstruction. Clamped so one oversized+ // request cannot exhaust IndexedDB; the marker mirrors tool-result+ // truncation ({ _truncated, length, head }).return _appendEvent(runId, 'llm_request', (state) => {if (state?.lossless === true && provenanceInput) {if ((state.losslessBytes || 0) >= LOSSILESS_RUN_CAP) {@@ -782,7 +881,7 @@ export function recordToolCall(runId, step, { name, args, result, latencyMs }) {export function recordScreenshot(runId, step, dataUrl, caption = '') {return _queueRunWrite(runId, async () => {- if (!(await tracingEnabled())) return;+ if (!(await tracingEnabledForRun(runId))) return;if (!dataUrl) return;try {const db = await openDB();@@ -809,6 +908,7 @@ export function recordScreenshot(runId, step, dataUrl, caption = '') {projectTraceEventData('screenshot', { step, caption }, { includeContent: state?.lossless === true }),);if (marker) {+ if (state?.feedbackOnly === true) return await writeFeedbackEvent(db, runId, marker, state);await promisifyReq(tx(db, ['events']).objectStore('events').put(marker));}return seq;@@ -916,7 +1016,7 @@ async function _retryCount(db, runId, step) {export function recordLLMRetry(runId, step, { delayMs = 0, code = 'UNKNOWN' } = {}) {return _queueRunWrite(runId, async () => {- if (!(await tracingEnabled())) return;+ if (!(await tracingEnabledForRun(runId))) return;try {const db = await openDB();await _ensureRunState(runId, db);@@ -942,14 +1042,15 @@ export async function endRun(runId, { status = 'done', finalContent = null } = {return _queueRunWrite(runId, async () => {let resolvedStatus = status;try {- if (!(await tracingEnabled())) {+ if (!(await tracingEnabledForRun(runId))) {_workflowTraceCaptures.delete(runId);return null;}const db = await openDB();- // Tally usage from events. `totalCost` is the sum of `usage.cost`- // across all llm_response events — providers report this in their- // native units (OpenRouter & OpenAI: USD).+ // Tally usage from events. `totalCost` is the sum of `usage.cost` across+ // all llm_response events — providers report this in their native units+ // (OpenRouter & OpenAI: USD). Surfaced in the Traces UI so users can+ // spot expensive-failure runs at a glance.const stats = createTraceStats();let sawLoopError = false;await new Promise((resolve) => {@@ -980,7 +1081,7 @@ export async function endRun(runId, { status = 'done', finalContent = null } = {existing.stepCount = stats.stepCount;existing.totalInputTokens = stats.totalInputTokens;existing.totalOutputTokens = stats.totalOutputTokens;- existing.totalCost = stats.totalCost;+ existing.totalCost = stats.totalCost; // null/0 when the provider didn't report costexisting.llmRequestCount = stats.llmRequestCount;existing.llmResponseCount = stats.llmResponseCount;existing.toolCallCount = stats.toolCallCount;@@ -996,8 +1097,11 @@ export async function endRun(runId, { status = 'done', finalContent = null } = {} finally {_runState.delete(runId);}+ // Retention may delete this run and its transient capture. Keep the+ // completed workflow independent of which diagnostics remain on disk.const workflowCapture = _workflowTraceCaptures.get(runId) || null;_workflowTraceCaptures.delete(runId);+ await pruneFeedbackDiagnostics().catch(() => {});if (!workflowCapture) return null;workflowCapture.run.status = resolvedStatus;return { run: workflowCapture.run, events: workflowCapture.events };@@ -1042,8 +1146,8 @@ export async function repairStaleRuns({const repaired = [];for (const candidate of candidates) {if (!isStaleRunningTrace(candidate, { now, staleAfterMs })) continue;- // A live run in this background instance is still owned by the agent.- // The durable marker handles races from another extension page.+ // A live run in this service-worker instance is still owned by the+ // agent. The durable marker handles races from another extension page.if (_runState.has(candidate.runId)) continue;await _flushRunWrites(candidate.runId);try {@@ -1070,6 +1174,7 @@ export async function flushPendingWrites() {}export async function listRuns({ limit = 500, conversationId = null } = {}) {+ await pruneFeedbackDiagnostics();const db = await openDB();const store = tx(db, ['runs'], 'readonly').objectStore('runs');const sessionQuery = Boolean(conversationId && store.indexNames.contains('sessionId'));diff --git a/src/firefox/src/ui/feedback-consent.css b/src/firefox/src/ui/feedback-consent.cssnew file mode 100644index 000000000..2b1972a1c--- /dev/null+++ b/src/firefox/src/ui/feedback-consent.css@@ -0,0 +1,14 @@+.feedback-trace-dialog {+ margin: auto;+ width: min(440px, calc(100vw - 48px)); max-height: calc(100vh - 48px);+ overflow: auto; padding: 20px; border: 1px solid var(--border, #8886);+ border-radius: 12px; background: var(--bg-secondary, Canvas); color: var(--text-primary, CanvasText);+ font: inherit; box-shadow: 0 12px 48px #0005;+}+.feedback-trace-dialog::backdrop { background: #0008; }+.feedback-trace-dialog h2 { font-size: 18px; margin: 0 0 12px; }+.feedback-trace-dialog p { line-height: 1.5; margin: 0 0 12px; }+.feedback-trace-details { overflow-wrap: anywhere; font-size: 12px; }+.feedback-trace-actions { display: grid; gap: 8px; }+.feedback-trace-actions button { white-space: normal; }+.feedback-trace-secondary { padding: 9px; border: 1px solid #8886; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }diff --git a/src/firefox/src/ui/feedback-consent.js b/src/firefox/src/ui/feedback-consent.jsnew file mode 100644index 000000000..0613ac470--- /dev/null+++ b/src/firefox/src/ui/feedback-consent.js@@ -0,0 +1,63 @@+import { formatFeedbackDetails } from './feedback-copy.js';++export function requestFeedbackConsent(trace, copy, viewTrace) {+ return new Promise(resolve => {+ const dialog = document.createElement('dialog');+ dialog.className = 'feedback-trace-dialog';+ dialog.setAttribute('aria-labelledby', 'feedback-trace-title');+ dialog.setAttribute('aria-describedby', 'feedback-trace-public');+ const previousFocus = document.activeElement;+ const text = (tag, value, id = '') => {+ const element = document.createElement(tag); element.textContent = value;+ if (id) element.id = id;+ dialog.append(element); return element;+ };+ text('h2', copy.title, 'feedback-trace-title');+ text('p', copy.publicWarning, 'feedback-trace-public');+ text('p', copy[trace.traceType]);+ text('p', formatFeedbackDetails(trace, copy)).className = 'feedback-trace-details';+ if (trace.omissions.length) text('p', trace.blob !== trace.originalBlob && trace.filename.endsWith('-diagnostics.json') ? copy.oversized : copy.omitted);+ const actions = text('div', ''); actions.className = 'feedback-trace-actions';+ const finish = choice => { dialog.close(); dialog.remove(); previousFocus?.focus(); resolve(choice); };+ for (const [choice, label] of [['view', copy.view], ['upload', copy.upload], ['without', copy.without], ['cancel', copy.cancel]]) {+ const button = document.createElement('button'); button.type = 'button'; button.textContent = label;+ button.dataset.feedbackChoice = choice;+ button.className = choice === 'upload' ? 'store-review-primary' : 'feedback-trace-secondary';+ button.addEventListener('click', () => choice === 'view' ? void viewTrace().catch(error => {+ text('p', error.message).setAttribute('role', 'alert');+ }) : finish(choice));+ actions.append(button);+ }+ dialog.addEventListener('cancel', event => { event.preventDefault(); finish('cancel'); });+ dialog.addEventListener('keydown', event => event.stopPropagation());+ document.body.append(dialog); dialog.showModal();+ actions.querySelector('[data-feedback-choice="cancel"]').focus();+ });+}++// The only call capable of opening the upload destination is after consent.+export async function submitFeedbackWithTrace({ prepare, stage, consent, discard, open, rating, comment, copy }) {+ let prepared, staged, traceNote = '', handedOff = false;+ try { prepared = await prepare(); } catch { traceNote = copy.exportFailed; }+ if (!prepared) {+ await open({ rating, comment, includeTrace: false, traceNote: traceNote || copy.unavailable, copy });+ return true;+ }+ staged = await stage(prepared);+ try {+ const choice = await consent(prepared, staged);+ if (choice === 'cancel') return false;+ const includeTrace = choice === 'upload';+ if (!includeTrace) await discard(staged.id);+ await open({ id: staged.id, rating, comment, includeTrace, copy,+ traceNote: includeTrace ? `${copy[`${prepared.traceType}Label`]} (${prepared.runCount} runs, ${prepared.screenshotCount} screenshots).`+ + (prepared.omissions.length ? ` ${copy.omitted}` : '') : '' });+ handedOff = includeTrace;+ return true;+ } catch (error) {+ await discard(staged.id); throw error;+ } finally {+ // The background owns an accepted handoff; keep its immutable bytes for retries.+ if (!handedOff) await discard(staged.id);+ }+}diff --git a/src/firefox/src/ui/feedback-copy.js b/src/firefox/src/ui/feedback-copy.jsnew file mode 100644index 000000000..e35f22615--- /dev/null+++ b/src/firefox/src/ui/feedback-copy.js@@ -0,0 +1,107 @@+const EN = {+ title: 'Share this trace on GitHub?',+ publicWarning: 'Uploading makes this file publicly accessible immediately, even if you never submit the GitHub issue.',+ full: 'Includes recorded conversation text, tool details, and any saved screenshots. Screenshots may contain private information. Obvious credentials are masked; review the trace before sharing.',+ diagnostic: 'Includes diagnostic metadata: tool names, outcomes, error codes, and timings. Conversation text and screenshots that were not recorded are unavailable.',+ upload: 'Upload trace and open GitHub', without: 'Continue without trace', cancel: 'Cancel', view: 'View trace',+ fullLabel: 'Full recorded trace', diagnosticLabel: 'Diagnostic trace',+ details: 'Conversation {session} · {type} · {runs} runs · {shots} screenshots · {size}',+ preparing: 'Preparing trace locally…',+ omitted: 'Recording or retention limits omitted some content. See the trace for details.',+ oversized: 'The full export is too large to attach. Only the diagnostic fallback will be uploaded. View trace to download the full export locally.',+ failed: 'The trace attachment could not be confirmed. Check the draft before retrying, or download the trace.',+ uploading: 'Attaching your trace. Please wait before submitting the issue.',+ ready: 'Trace attached. Review and submit your feedback on GitHub.',+ draftReady: 'Review and submit your feedback on GitHub.',+ retry: 'Retry attachment', download: 'Download trace', close: 'Close',+ local: 'Local preview. Nothing is uploaded by viewing or downloading this trace.',+ original: 'Download full export', previewLimited: 'Preview shortened. Download the export to inspect the complete file.',+ unavailable: 'No recorded trace is available for this conversation.',+ exportFailed: 'The trace could not be read; no trace is attached.',+ settingLabel: 'Local feedback diagnostics',+ settingDescription: 'Keep recent diagnostic metadata locally, even when Record traces is off. Limited to 10 completed runs, 7 days, and 2 MiB. Upload requires confirmation when sending feedback; conversation text and screenshots are not recorded by this option.',+};++// Keep the consequential disclosure and actions translated for every UI locale.+// Secondary status text uses the same English fallback as the main UI.+const CORE = {+ ru: ['Поделиться этой трассировкой на GitHub?', 'Файл станет общедоступным сразу после загрузки, даже если вы не отправите обращение на GitHub.', 'Загрузить трассировку и открыть GitHub', 'Продолжить без трассировки', 'Отмена', 'Посмотреть трассировку'],+ ar: ['مشاركة هذا التتبع على GitHub؟', 'يصبح هذا الملف متاحًا للجميع فور رفعه، حتى لو لم ترسل المشكلة على GitHub.', 'رفع التتبع وفتح GitHub', 'المتابعة دون تتبع', 'إلغاء', 'عرض التتبع'],+ bn: ['এই ট্রেস GitHub-এ শেয়ার করবেন?', 'আপলোড করলেই ফাইলটি সবার জন্য উন্মুক্ত হবে, আপনি GitHub ইস্যু জমা না দিলেও।', 'ট্রেস আপলোড করে GitHub খুলুন', 'ট্রেস ছাড়া চালিয়ে যান', 'বাতিল', 'ট্রেস দেখুন'],+ de: ['Diesen Trace auf GitHub teilen?', 'Die Datei ist sofort nach dem Hochladen öffentlich zugänglich, auch wenn du das GitHub-Issue nie absendest.', 'Trace hochladen und GitHub öffnen', 'Ohne Trace fortfahren', 'Abbrechen', 'Trace ansehen'],+ es: ['¿Compartir esta traza en GitHub?', 'El archivo será público inmediatamente al subirlo, aunque nunca envíes la incidencia de GitHub.', 'Subir traza y abrir GitHub', 'Continuar sin traza', 'Cancelar', 'Ver traza'],+ fa: ['این ردگیری در GitHub به اشتراک گذاشته شود؟', 'فایل بلافاصله پس از بارگذاری برای همه قابل دسترسی میشود، حتی اگر گزارش GitHub را ارسال نکنید.', 'بارگذاری ردگیری و باز کردن GitHub', 'ادامه بدون ردگیری', 'لغو', 'مشاهده ردگیری'],+ fr: ['Partager cette trace sur GitHub ?', 'Le fichier devient public dès son téléversement, même si vous ne soumettez jamais le ticket GitHub.', 'Téléverser la trace et ouvrir GitHub', 'Continuer sans trace', 'Annuler', 'Voir la trace'],+ he: ['לשתף את התיעוד הזה ב-GitHub?', 'הקובץ יהיה נגיש לציבור מיד לאחר ההעלאה, גם אם לא תשלחו את הדיווח ב-GitHub.', 'העלאת התיעוד ופתיחת GitHub', 'המשך ללא תיעוד', 'ביטול', 'הצגת התיעוד'],+ hi: ['यह ट्रेस GitHub पर साझा करें?', 'अपलोड होते ही फ़ाइल सार्वजनिक हो जाएगी, भले ही आप GitHub समस्या कभी जमा न करें।', 'ट्रेस अपलोड करें और GitHub खोलें', 'ट्रेस के बिना जारी रखें', 'रद्द करें', 'ट्रेस देखें'],+ id: ['Bagikan trace ini di GitHub?', 'Berkas langsung dapat diakses publik setelah diunggah, meskipun Anda tidak pernah mengirim issue GitHub.', 'Unggah trace dan buka GitHub', 'Lanjutkan tanpa trace', 'Batal', 'Lihat trace'],+ ja: ['このトレースをGitHubで共有しますか?', 'アップロードすると、GitHubのIssueを送信しなくても、ファイルは直ちに公開されます。', 'トレースをアップロードしてGitHubを開く', 'トレースなしで続行', 'キャンセル', 'トレースを表示'],+ ko: ['이 트레이스를 GitHub에 공유할까요?', '업로드하면 GitHub 이슈를 제출하지 않아도 파일이 즉시 공개됩니다.', '트레이스 업로드 후 GitHub 열기', '트레이스 없이 계속', '취소', '트레이스 보기'],+ ms: ['Kongsi jejak ini di GitHub?', 'Fail boleh diakses umum serta-merta selepas dimuat naik, walaupun anda tidak menghantar isu GitHub.', 'Muat naik jejak dan buka GitHub', 'Teruskan tanpa jejak', 'Batal', 'Lihat jejak'],+ nl: ['Deze trace op GitHub delen?', 'Het bestand is direct na het uploaden openbaar, ook als je het GitHub-issue nooit indient.', 'Trace uploaden en GitHub openen', 'Doorgaan zonder trace', 'Annuleren', 'Trace bekijken'],+ pl: ['Udostępnić ten ślad na GitHub?', 'Plik stanie się publicznie dostępny natychmiast po przesłaniu, nawet jeśli nie wyślesz zgłoszenia GitHub.', 'Prześlij ślad i otwórz GitHub', 'Kontynuuj bez śladu', 'Anuluj', 'Zobacz ślad'],+ pt: ['Compartilhar este rastreamento no GitHub?', 'O arquivo ficará público imediatamente após o envio, mesmo que você nunca publique a issue no GitHub.', 'Enviar rastreamento e abrir GitHub', 'Continuar sem rastreamento', 'Cancelar', 'Ver rastreamento'],+ th: ['แชร์บันทึกนี้บน GitHub หรือไม่?', 'ไฟล์จะเปิดให้สาธารณะเข้าถึงได้ทันทีที่อัปโหลด แม้คุณจะไม่ส่งปัญหาบน GitHub ก็ตาม', 'อัปโหลดบันทึกและเปิด GitHub', 'ดำเนินการต่อโดยไม่แนบบันทึก', 'ยกเลิก', 'ดูบันทึก'],+ tl: ['Ibahagi ang trace na ito sa GitHub?', 'Magiging pampubliko agad ang file kapag na-upload, kahit hindi mo isumite ang GitHub issue.', 'I-upload ang trace at buksan ang GitHub', 'Magpatuloy nang walang trace', 'Kanselahin', 'Tingnan ang trace'],+ tr: ['Bu izi GitHub’da paylaşmak ister misiniz?', 'Dosya yüklendiği anda herkese açık olur; GitHub sorununu göndermeseniz bile dosyaya erişilebilir.', 'İzi yükle ve GitHub’ı aç', 'İz olmadan devam et', 'İptal', 'İzi görüntüle'],+ uk: ['Поділитися цим трасуванням на GitHub?', 'Файл стане загальнодоступним одразу після завантаження, навіть якщо ви не надішлете звернення на GitHub.', 'Завантажити трасування й відкрити GitHub', 'Продовжити без трасування', 'Скасувати', 'Переглянути трасування'],+ vi: ['Chia sẻ dấu vết này trên GitHub?', 'Tệp sẽ công khai ngay khi tải lên, kể cả khi bạn không gửi vấn đề trên GitHub.', 'Tải dấu vết lên và mở GitHub', 'Tiếp tục không kèm dấu vết', 'Hủy', 'Xem dấu vết'],+ zh: ['在 GitHub 上分享此跟踪记录?', '上传后文件会立即公开,即使您最终没有提交 GitHub 问题。', '上传跟踪记录并打开 GitHub', '不附带跟踪记录继续', '取消', '查看跟踪记录'],+};+const CONTENT = {+ ar: ['يتضمن نص المحادثة وتفاصيل الأدوات ولقطات الشاشة المحفوظة، إن وُجدت. تُخفى بيانات الاعتماد الواضحة؛ راجع الملف قبل مشاركته.', 'يتضمن بيانات تشخيصية فقط: أسماء الأدوات والنتائج ورموز الأخطاء والتوقيتات. لا تتوفر النصوص أو الصور غير المسجلة.'],+ bn: ['সংরক্ষিত কথোপকথন, টুলের বিবরণ ও উপলব্ধ স্ক্রিনশট অন্তর্ভুক্ত থাকে। স্পষ্ট পরিচয়পত্র গোপন করা হয়; শেয়ার করার আগে ফাইলটি দেখুন।', 'শুধু ডায়াগনস্টিক তথ্য থাকে: টুলের নাম, ফলাফল, ত্রুটি কোড ও সময়। রেকর্ড না করা লেখা বা স্ক্রিনশট নেই।'],+ de: ['Enthält aufgezeichnete Gespräche, Werkzeugdetails und vorhandene Screenshots. Offensichtliche Zugangsdaten werden maskiert; prüfe die Datei vor dem Teilen.', 'Enthält nur Diagnosedaten: Werkzeugnamen, Ergebnisse, Fehlercodes und Zeitangaben. Nicht aufgezeichnete Texte und Screenshots sind nicht verfügbar.'],+ es: ['Incluye conversaciones grabadas, detalles de herramientas y capturas disponibles. Se ocultan las credenciales evidentes; revisa el archivo antes de compartirlo.', 'Solo incluye datos de diagnóstico: nombres de herramientas, resultados, códigos de error y tiempos. Los textos y capturas no grabados no están disponibles.'],+ fa: ['شامل گفتوگوی ثبتشده، جزئیات ابزارها و تصاویر ذخیرهشده است. اطلاعات ورود آشکار پوشانده میشوند؛ پیش از اشتراکگذاری فایل را بررسی کنید.', 'فقط شامل اطلاعات تشخیصی است: نام ابزارها، نتایج، کدهای خطا و زمانها. متن و تصاویر ثبتنشده موجود نیستند.'],+ he: ['כולל שיחות שהוקלטו, פרטי כלים וצילומי מסך זמינים. פרטי גישה ברורים מוסתרים; בדקו את הקובץ לפני השיתוף.', 'כולל רק נתוני אבחון: שמות כלים, תוצאות, קודי שגיאה וזמנים. טקסט ותמונות שלא תועדו אינם זמינים.'],+ hi: ['रिकॉर्ड की गई बातचीत, टूल विवरण और उपलब्ध स्क्रीनशॉट शामिल हैं। स्पष्ट लॉगिन जानकारी छिपाई जाती है; साझा करने से पहले फ़ाइल देखें।', 'केवल निदान जानकारी: टूल के नाम, परिणाम, त्रुटि कोड और समय। रिकॉर्ड न किया गया पाठ या स्क्रीनशॉट उपलब्ध नहीं है।'],+ id: ['Berisi percakapan yang direkam, detail alat, dan tangkapan layar yang tersedia. Kredensial yang jelas disamarkan; periksa berkas sebelum berbagi.', 'Hanya berisi diagnostik: nama alat, hasil, kode kesalahan, dan waktu. Teks dan tangkapan layar yang tidak direkam tidak tersedia.'],+ ja: ['記録された会話、ツールの詳細、保存済みのスクリーンショットを含みます。明らかな認証情報はマスクされます。共有前にファイルを確認してください。', 'ツール名、結果、エラーコード、時間などの診断情報のみを含みます。記録されていない会話やスクリーンショットは含まれません。'],+ ko: ['기록된 대화, 도구 세부 정보 및 저장된 스크린샷을 포함합니다. 명백한 인증 정보는 가려집니다. 공유하기 전에 파일을 확인하세요.', '도구 이름, 결과, 오류 코드 및 시간 등 진단 정보만 포함합니다. 기록하지 않은 대화나 스크린샷은 제공되지 않습니다.'],+ ms: ['Mengandungi perbualan yang direkodkan, butiran alat dan tangkapan skrin yang tersedia. Bukti kelayakan yang jelas disamarkan; semak fail sebelum berkongsi.', 'Hanya mengandungi diagnostik: nama alat, hasil, kod ralat dan masa. Teks dan tangkapan skrin yang tidak direkodkan tidak tersedia.'],+ nl: ['Bevat opgenomen gesprekken, tooldetails en beschikbare schermafbeeldingen. Duidelijke inloggegevens worden afgeschermd; controleer het bestand voordat je het deelt.', 'Bevat alleen diagnostiek: toolnamen, resultaten, foutcodes en tijden. Niet opgenomen tekst en schermafbeeldingen zijn niet beschikbaar.'],+ pl: ['Zawiera zapisane rozmowy, szczegóły narzędzi i dostępne zrzuty ekranu. Oczywiste dane logowania są maskowane; sprawdź plik przed udostępnieniem.', 'Zawiera tylko diagnostykę: nazwy narzędzi, wyniki, kody błędów i czasy. Niezapisane teksty i zrzuty ekranu nie są dostępne.'],+ pt: ['Inclui conversas gravadas, detalhes de ferramentas e capturas disponíveis. Credenciais evidentes são ocultadas; revise o arquivo antes de compartilhar.', 'Inclui apenas diagnóstico: nomes de ferramentas, resultados, códigos de erro e tempos. Textos e capturas não gravados não estão disponíveis.'],+ ru: ['Содержит записанные разговоры, детали инструментов и сохранённые снимки экрана. Очевидные учётные данные маскируются; проверьте файл перед отправкой.', 'Содержит только диагностику: имена инструментов, результаты, коды ошибок и время. Незаписанный текст и снимки экрана недоступны.'],+ th: ['รวมบทสนทนาที่บันทึกไว้ รายละเอียดเครื่องมือ และภาพหน้าจอที่มีอยู่ ข้อมูลรับรองที่ชัดเจนจะถูกปิดบัง โปรดตรวจสอบไฟล์ก่อนแชร์', 'มีเฉพาะข้อมูลวินิจฉัย: ชื่อเครื่องมือ ผลลัพธ์ รหัสข้อผิดพลาด และเวลา ไม่มีข้อความหรือภาพหน้าจอที่ไม่ได้บันทึกไว้'],+ tl: ['Kasama ang naitalang usapan, detalye ng mga tool, at available na screenshot. Itinatago ang malinaw na kredensyal; suriin ang file bago ibahagi.', 'Diagnostic data lamang: pangalan ng mga tool, resulta, error code, at oras. Walang tekstong o screenshot na hindi naitala.'],+ uk: ['Містить записані розмови, деталі інструментів і збережені знімки екрана. Очевидні облікові дані маскуються; перевірте файл перед надсиланням.', 'Містить лише діагностику: назви інструментів, результати, коди помилок і час. Незаписаний текст і знімки екрана недоступні.'],+ vi: ['Gồm cuộc trò chuyện đã ghi, chi tiết công cụ và ảnh chụp màn hình có sẵn. Thông tin đăng nhập rõ ràng được che; hãy xem tệp trước khi chia sẻ.', 'Chỉ gồm chẩn đoán: tên công cụ, kết quả, mã lỗi và thời gian. Văn bản và ảnh chụp chưa ghi không có sẵn.'],+ zh: ['包含已记录的对话、工具详情和已保存的截图。明显的凭据会被遮盖;分享前请检查文件。', '仅包含诊断信息:工具名称、结果、错误代码和时间。未记录的对话文本和截图不可用。'],+};+const EXTRA = {+ tr: {+ full: 'Kaydedilmiş konuşma metni, araç ayrıntıları ve varsa ekran görüntülerini içerir. Ekran görüntülerinde özel bilgiler olabilir. Belirgin kimlik bilgileri maskelenir; paylaşmadan önce izi inceleyin.',+ diagnostic: 'Araç adları, sonuçlar, hata kodları ve süreler gibi tanılama bilgilerini içerir. Kaydedilmemiş konuşma metni ve ekran görüntüleri mevcut değildir.',+ fullLabel: 'Tam kaydedilmiş iz', diagnosticLabel: 'Tanılama izi',+ details: 'Konuşma {session} · {type} · {runs} çalışma · {shots} ekran görüntüsü · {size}',+ preparing: 'İz yerel olarak hazırlanıyor…', settingLabel: 'Yerel geri bildirim tanılaması',+ settingDescription: 'İz kaydı kapalı olsa da son tanılama bilgilerini cihazda saklar. En fazla 10 tamamlanan çalışma, 7 gün ve 2 MiB. Geri bildirim gönderirken yükleme için onay gerekir; bu seçenek konuşma metni veya ekran görüntüsü kaydetmez.',+ },+ fr: {+ full: 'Contient le texte de conversation enregistré, les détails des outils et les captures conservées. Les captures peuvent contenir des informations privées. Les identifiants évidents sont masqués ; vérifiez la trace avant de la partager.',+ diagnostic: 'Contient les noms des outils, les résultats, les codes d’erreur et les durées. Le texte et les captures non enregistrés ne sont pas disponibles.',+ fullLabel: 'Trace enregistrée complète', diagnosticLabel: 'Trace de diagnostic',+ details: 'Conversation {session} · {type} · {runs} exécutions · {shots} captures · {size}',+ },+};+export function getFeedbackCopy(locale = 'en') {+ const copy = { ...EN, ...EXTRA[locale] };+ if (CORE[locale]) ['title', 'publicWarning', 'upload', 'without', 'cancel', 'view'].forEach((key, index) => { copy[key] = CORE[locale][index]; });+ if (CONTENT[locale]) [copy.full, copy.diagnostic] = CONTENT[locale];+ return copy;+}+export function formatFeedbackDetails(trace, copy) {+ const values = { session: trace.sessionId, type: copy[`${trace.traceType}Label`],+ runs: trace.runCount, shots: trace.screenshotCount, size: `${(trace.blob.size / 1024).toFixed(1)} KiB` };+ return copy.details.replace(/\{(\w+)\}/g, (_, key) => values[key] ?? '');+}++export const feedbackTranslations = Object.fromEntries(['en', ...Object.keys(CORE)].map(locale => {+ const copy = getFeedbackCopy(locale);+ return [locale, {+ 'st.display.feedback_diagnostics.label': copy.settingLabel,+ 'st.display.feedback_diagnostics.desc': copy.settingDescription,+ }];+}));diff --git a/src/firefox/src/ui/feedback-trace-preview.css b/src/firefox/src/ui/feedback-trace-preview.cssnew file mode 100644index 000000000..276b23d6a--- /dev/null+++ b/src/firefox/src/ui/feedback-trace-preview.css@@ -0,0 +1,4 @@+:root { color-scheme: light dark; font: 15px/1.5 system-ui; }+body { margin: 24px; } main { max-width: 1100px; margin: auto; }+pre { white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid #8886; padding: 16px; border-radius: 8px; }+button { padding: 8px 16px; margin-right: 8px; cursor: pointer; }diff --git a/src/firefox/src/ui/feedback-trace-preview.html b/src/firefox/src/ui/feedback-trace-preview.htmlnew file mode 100644index 000000000..e9244c625--- /dev/null+++ b/src/firefox/src/ui/feedback-trace-preview.html@@ -0,0 +1,7 @@+<!doctype html>+<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">+<title>WebBrain trace preview</title><script src="theme-bootstrap.js"></script>+<link rel="stylesheet" href="feedback-trace-preview.css"></head>+<body><main><h1 id="title">WebBrain trace preview</h1><p id="notice"></p><p id="details"></p>+<button type="button" id="download"></button><button type="button" id="download-original" hidden></button>+<p id="limit"></p><pre id="preview"></pre></main><script type="module" src="feedback-trace-preview.js"></script></body></html>diff --git a/src/firefox/src/ui/feedback-trace-preview.js b/src/firefox/src/ui/feedback-trace-preview.jsnew file mode 100644index 000000000..a8afd9849--- /dev/null+++ b/src/firefox/src/ui/feedback-trace-preview.js@@ -0,0 +1,34 @@+import { getFeedbackDraft } from '../feedback-store.js';+import { getFeedbackCopy, formatFeedbackDetails } from './feedback-copy.js';+import { getLocale } from './i18n.js';++let copy = getFeedbackCopy(getLocale());+document.getElementById('title').textContent = copy.view;+document.getElementById('notice').textContent = copy.local;+function download(blob, filename) {+ const url = URL.createObjectURL(blob), anchor = document.createElement('a');+ anchor.href = url; anchor.download = filename; anchor.click();+ setTimeout(() => URL.revokeObjectURL(url), 1000);+}+try {+ const draft = await getFeedbackDraft(new URL(location.href).searchParams.get('id'));+ if (!draft?.blob || draft.expiresAt <= Date.now()) throw new Error(copy.unavailable);+ copy = draft.copy || copy;+ document.getElementById('title').textContent = copy.view;+ document.getElementById('notice').textContent = copy.local;+ document.getElementById('details').textContent = formatFeedbackDetails(draft, copy);+ // The original uncompressed JSON is retained only locally, including when+ // the consent dialog proposes a smaller diagnostic fallback.+ const previewBlob = draft.filename.endsWith('-diagnostics.json') ? draft.blob : draft.originalBlob;+ document.getElementById('preview').textContent = await previewBlob.slice(0, 500_000).text();+ if (previewBlob.size > 500_000) document.getElementById('limit').textContent = copy.previewLimited;+ const button = document.getElementById('download'); button.textContent = copy.download;+ button.addEventListener('click', () => download(draft.blob, draft.filename));+ if (draft.blob.size !== draft.originalBlob.size) {+ const original = document.getElementById('download-original'); original.hidden = false; original.textContent = copy.original;+ original.addEventListener('click', () => download(draft.originalBlob, 'webbrain-feedback-full.json'));+ }+} catch (error) {+ document.getElementById('preview').textContent = error.message;+ document.getElementById('download').hidden = true;+}diff --git a/src/firefox/src/ui/i18n.js b/src/firefox/src/ui/i18n.jsindex 691ec2c94..dbf924eeb 100644--- a/src/firefox/src/ui/i18n.js+++ b/src/firefox/src/ui/i18n.js@@ -4,6 +4,7 @@ import { decisionEnglish, decisionTranslations } from './locales/decision-copy.m// Works identically in Chrome MV3 and Firefox MV2.import en from './locales/en.js';+import { feedbackTranslations } from './feedback-copy.js';import { quotaTranslations } from './locales/compass-quota-copy.mjs';import { memcodeEnglish } from './locales/memcode-copy.mjs';import { captchaEnglish, captchaTranslations } from './locales/captcha-copy.mjs';@@ -37,6 +38,7 @@ import { providerGuideEnglish, providerGuideTranslations } from './locales/proviconst DICTS = Object.fromEntries(Object.entries({ en, es, fr, tr, zh, ru, uk, ar, ja, ko, id, th, ms, tl, pl, he, hi, pt, vi, bn, fa, nl, de }).map(([code, dict]) => [code, {...dict,+ ...feedbackTranslations[code],...(composerDeliveryTranslations[code] || {}),...(cloudBridgeTranslations[code] || {}),...quotaTranslations[code],diff --git a/src/firefox/src/ui/settings.html b/src/firefox/src/ui/settings.htmlindex 7992ad0ae..6ef1c3210 100644--- a/src/firefox/src/ui/settings.html+++ b/src/firefox/src/ui/settings.html@@ -1547,6 +1547,16 @@<span class="toggle-slider"></span></label></div>+ <div class="setting-row">+ <div class="setting-info">+ <div class="setting-label" data-i18n="st.display.feedback_diagnostics.label"></div>+ <div class="setting-desc" data-i18n="st.display.feedback_diagnostics.desc"></div>+ </div>+ <label class="toggle">+ <input type="checkbox" id="toggle-feedback-diagnostics" checked>+ <span class="toggle-slider"></span>+ </label>+ </div><div class="setting-row"><div class="setting-info"><div class="setting-label" data-i18n="st.display.verbose.label"></div>diff --git a/src/firefox/src/ui/settings.js b/src/firefox/src/ui/settings.jsindex 5ac9b2c2f..ffb154e5b 100644--- a/src/firefox/src/ui/settings.js+++ b/src/firefox/src/ui/settings.js@@ -126,6 +126,7 @@ const notifySoundToggle = document.getElementById('toggle-notify-sound');const completionConfettiToggle = document.getElementById('toggle-completion-confetti');const completionFlashTabToggle = document.getElementById('toggle-completion-flash-tab');const tracingToggle = document.getElementById('toggle-tracing');+const feedbackDiagnosticsToggle = document.getElementById('toggle-feedback-diagnostics');const losslessTracingToggle = document.getElementById('toggle-lossless-tracing');const strictSecretToggle = document.getElementById('toggle-strict-secret');const allowLocalNetworkToggle = document.getElementById('toggle-allow-local-network');@@ -602,7 +603,7 @@ async function init() {browser.storage.local.remove(['authToken', 'authEmail', 'authDefaultModel']).catch(() => {});// Load display settings- const stored = await browser.storage.local.get([...DECISION_SETTINGS_KEYS, 'verboseMode', 'composerDeliveryMode', 'selectionShortcutEnabled', AUTO_GROUP_TABS_KEY, 'helpImproveWebBrain', 'screenshotFallback', 'maxAgentSteps', 'autoScreenshot', 'useSiteAdapters', 'researchEscalationEnabled', 'researchEscalationEngine', 'voiceInputEnabled', 'alwaysAllowApiMutations', 'apiMutationObserverEnabled', 'openaiAskStreamingEnabled', 'planBeforeActMode', 'planBeforeAct', 'planReviewMode', 'planReviewConfidenceThreshold', DOWNLOAD_DIRECTORY_STORAGE_KEY, 'notifySound', 'completionConfetti', 'completionFlashTab', 'tracingEnabled', 'losslessTrace', 'strictSecretMode', 'agentAllowLocalNetwork', 'scheduledTasksEnabled', 'scheduledRequireConsequentialConfirmation', 'systemOneEnabled', 'systemOneWatchEnabled', 'systemOneCompletionEnabled', 'systemOneFastClassifications', 'systemOneFastBrowser', 'systemOneWatchThreshold', 'systemOneCompletionThreshold', 'typesafeApiKey', 'providerFilter', 'requestTimeoutMs', 'clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'costAllowanceSessionUsd', 'costAllowanceTotalUsd', 'meteredProviderCostSpentUsd', 'screenshotRedaction', 'imageDetail', 'maxScreenshotsPerTurn', 'maxImageDimension']);+ const stored = await browser.storage.local.get([...DECISION_SETTINGS_KEYS, 'verboseMode', 'composerDeliveryMode', 'selectionShortcutEnabled', AUTO_GROUP_TABS_KEY, 'helpImproveWebBrain', 'screenshotFallback', 'maxAgentSteps', 'autoScreenshot', 'useSiteAdapters', 'researchEscalationEnabled', 'researchEscalationEngine', 'voiceInputEnabled', 'alwaysAllowApiMutations', 'apiMutationObserverEnabled', 'openaiAskStreamingEnabled', 'planBeforeActMode', 'planBeforeAct', 'planReviewMode', 'planReviewConfidenceThreshold', DOWNLOAD_DIRECTORY_STORAGE_KEY, 'notifySound', 'completionConfetti', 'completionFlashTab', 'tracingEnabled', 'feedbackDiagnosticsEnabled', 'losslessTrace', 'strictSecretMode', 'agentAllowLocalNetwork', 'scheduledTasksEnabled', 'scheduledRequireConsequentialConfirmation', 'systemOneEnabled', 'systemOneWatchEnabled', 'systemOneCompletionEnabled', 'systemOneFastClassifications', 'systemOneFastBrowser', 'systemOneWatchThreshold', 'systemOneCompletionThreshold', 'typesafeApiKey', 'providerFilter', 'requestTimeoutMs', 'clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'costAllowanceSessionUsd', 'costAllowanceTotalUsd', 'meteredProviderCostSpentUsd', 'screenshotRedaction', 'imageDetail', 'maxScreenshotsPerTurn', 'maxImageDimension']);if (typeof stored.providerFilter === 'string' && ['all','active','local','cloud','router'].includes(stored.providerFilter)) {providerFilter = stored.providerFilter;}@@ -672,6 +673,7 @@ async function init() {if (completionConfettiToggle) completionConfettiToggle.checked = stored.completionConfetti ?? true;if (completionFlashTabToggle) completionFlashTabToggle.checked = stored.completionFlashTab ?? true;if (tracingToggle) tracingToggle.checked = stored.tracingEnabled === true;+ if (feedbackDiagnosticsToggle) feedbackDiagnosticsToggle.checked = stored.feedbackDiagnosticsEnabled !== false;if (losslessTracingToggle) {losslessTracingToggle.checked = stored.losslessTrace === true;// Lossless recording only means something when tracing is on; mirror the@@ -1446,6 +1448,14 @@ losslessTracingToggle?.addEventListener('change', async () => {await browser.storage.local.set({ losslessTrace: losslessTracingToggle.checked }).catch(() => {});});+feedbackDiagnosticsToggle?.addEventListener('change', async () => {+ await browser.storage.local.set({ feedbackDiagnosticsEnabled: feedbackDiagnosticsToggle.checked });+ if (!feedbackDiagnosticsToggle.checked) {+ const response = await browser.runtime.sendMessage({ target: 'background', action: 'feedback_clear_diagnostics' });+ if (!response?.ok) console.error('[feedback] Could not clear local diagnostics:', response?.error);+ }+});+costSessionLimitInput?.addEventListener('change', async () => {const value = normalizeCostAmount(costSessionLimitInput.value);costSessionLimitInput.value = value.toFixed(2);diff --git a/src/firefox/src/ui/sidepanel.html b/src/firefox/src/ui/sidepanel.htmlindex 7bf1114a3..8efa61617 100644--- a/src/firefox/src/ui/sidepanel.html+++ b/src/firefox/src/ui/sidepanel.html@@ -12,6 +12,7 @@<script src="theme-bootstrap.js"></script><link rel="stylesheet" href="../../styles/sidepanel.css"><link rel="stylesheet" href="offline-rag-readiness.css">+ <link rel="stylesheet" href="feedback-consent.css"><link rel="stylesheet" href="../../vendor/katex/katex.min.css"><!-- KaTeX is loaded as classic scripts (not modules). They assign towindow.katex and window.renderMathInElement so formatMarkdown candiff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex c69cb204b..4b7876965 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -72,6 +72,8 @@ import {normalizeState as normalizeStoreReviewState,} from './store-review-prompt.js';import { providerIconUrl } from './provider-icons.js';+import { getFeedbackCopy } from './feedback-copy.js';+import { requestFeedbackConsent, submitFeedbackWithTrace } from './feedback-consent.js';import { parseWatchSlashCommand, WATCH_COMMAND_USAGE } from './watch-command.js';import { createSidePanelWindowScope } from './sidepanel-window-scope.js';import { visionProviderKind } from '../providers/vision-capabilities.js';@@ -1500,6 +1502,8 @@ function getExtensionStoreKey() {let storeReviewState = normalizeStoreReviewState(null);let storeReviewSelectedRating = null;+let storeReviewTraceSource = Promise.resolve(null);+let storeReviewSending = false;async function loadStoreReviewState() {const stored = await browser.storage.local.get(STORE_REVIEW_STORAGE_KEY);@@ -1533,6 +1537,10 @@ function setStoreReviewStarPreview(rating) {async function openStoreReviewPrompt() {if (!storeReviewEl || isProcessing) return;+ // Freeze the session before tabs or conversations can change beneath the prompt.+ const sourceTabId = currentTabId;+ storeReviewTraceSource = sourceTabId == null ? Promise.resolve(null)+ : sendToBackground('export_traces', { tabId: sourceTabId, full: true }).catch(() => null);storeReviewSelectedRating = null;if (storeReviewFeedbackEl) storeReviewFeedbackEl.value = '';setStoreReviewStarPreview(null);@@ -1578,15 +1586,54 @@ async function handleStoreReviewOpenStore() {}async function handleStoreReviewSendFeedback() {+ if (storeReviewSending) return;+ storeReviewSending = true;const rating = storeReviewSelectedRating || storeReviewState.rating || 3;const comment = storeReviewFeedbackEl?.value || '';+ const copy = getFeedbackCopy(getLocale());+ const button = document.getElementById('store-review-send-feedback');+ const previousLabel = button?.textContent;+ if (button) { button.disabled = true; button.textContent = copy.preparing; }try {- browser.tabs.create({ url: buildFeedbackUrl({ rating, comment }) });- } catch { /* ignore */ }- const next = markFeedbackSubmitted(storeReviewState);- await saveStoreReviewState(next);- showStoreReviewStep('thanks');- setTimeout(() => hideStoreReviewPrompt(), 2500);+ const { stageFeedbackTrace, deleteFeedbackDraft } = await import('../feedback-store.js');+ const source = await storeReviewTraceSource;+ const completed = await submitFeedbackWithTrace({+ rating, comment, copy,+ prepare: async () => {+ if (!source?.sessionId) return null;+ const flushed = await sendToBackground('feedback_flush');+ if (!flushed?.ok) throw new Error(flushed?.error || 'Trace flush failed.');+ const [store, { prepareFeedbackTrace }] = await Promise.all([+ import('../trace/recorder.js'), import('../trace/feedback-export.js'),+ ]);+ return prepareFeedbackTrace(store, source.sessionId, browser.runtime.getManifest().version || '');+ },+ stage: prepared => stageFeedbackTrace({ ...prepared, copy }),+ discard: deleteFeedbackDraft,+ consent: (prepared, staged) => requestFeedbackConsent(prepared, copy, () => browser.tabs.create({+ url: browser.runtime.getURL(`src/ui/feedback-trace-preview.html?id=${encodeURIComponent(staged.id)}`),+ })),+ open: async params => {+ if (!params.includeTrace) {+ await browser.tabs.create({ url: buildFeedbackUrl(params) });+ return;+ }+ const result = await sendToBackground('feedback_open', params);+ if (!result?.ok) throw new Error(result?.error || 'Could not open feedback.');+ },+ });+ if (!completed) return;+ await saveStoreReviewState(markFeedbackSubmitted(storeReviewState));+ showStoreReviewStep('thanks');+ const thanks = document.querySelector('#store-review-step-thanks .store-review-body');+ if (thanks) thanks.textContent = copy.draftReady;+ setTimeout(() => hideStoreReviewPrompt(), 2500);+ } catch (error) {+ showComposerToast(error?.message || String(error));+ } finally {+ storeReviewSending = false;+ if (button) { button.disabled = false; button.textContent = previousLabel; }+ }}function initStoreReviewPrompt() {diff --git a/src/firefox/src/ui/store-review-prompt.js b/src/firefox/src/ui/store-review-prompt.jsindex 0356ddafc..1c52388bf 100644--- a/src/firefox/src/ui/store-review-prompt.js+++ b/src/firefox/src/ui/store-review-prompt.js@@ -110,16 +110,21 @@ export function getStoreUrl(browserKey = 'chrome') {return STORE_URLS[browserKey] || STORE_URLS.chrome;}-export function buildFeedbackUrl({ rating, comment = '' } = {}) {- const title = encodeURIComponent(`WebBrain feedback (${rating}/5)`);+export function buildFeedbackBody({ rating, comment = '', traceNote = '' } = {}) {const bodyParts = [`**Rating:** ${rating}/5`,'',String(comment || '').trim() || '_No additional comments provided._',+ ...(traceNote ? ['', `**Trace:** ${String(traceNote)}`] : []),'','---','_Submitted from the WebBrain side panel feedback prompt._',];- const body = encodeURIComponent(bodyParts.join('\n'));+ return bodyParts.join('\n');+}++export function buildFeedbackUrl({ rating, comment = '', traceNote = '' } = {}) {+ const title = encodeURIComponent(`WebBrain feedback (${rating}/5)`);+ const body = encodeURIComponent(buildFeedbackBody({ rating, comment, traceNote }));return `${FEEDBACK_ISSUES_URL}?title=${title}&body=${body}`;}diff --git a/test/feedback-traces.mjs b/test/feedback-traces.mjsnew file mode 100644index 000000000..dec524e3d--- /dev/null+++ b/test/feedback-traces.mjs@@ -0,0 +1,474 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { readFile, mkdir, mkdtemp } from 'node:fs/promises';+import { resolve, sep } from 'node:path';+import { gunzipSync } from 'node:zlib';+import vm from 'node:vm';+import { chromium, firefox } from 'playwright';++for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {+ const { prepareFeedbackTrace } = await import(`../src/${build}/src/trace/feedback-export.js`);+ const { submitFeedbackWithTrace } = await import(`../src/${build}/src/ui/feedback-consent.js`);+ const { getFeedbackCopy } = await import(`../src/${build}/src/ui/feedback-copy.js`);+ const { feedbackRecordingPolicy, feedbackRunsToEvict } = await import(`../src/${build}/src/trace/feedback-policy.js`);+ const { createConfigExport, parseConfigImport } = await import(`../src/${build}/src/config-transfer.js`);+ const { mayReadFeedbackDraft, isFeedbackDestination } = await import(`../src/${build}/src/feedback-handoff.js`);+ const { sanitizeTraceExport } = await import(`../src/${build}/src/agent/trace-export.js`);+ const fixtureStore = (events = []) => ({+ listRuns: async () => [{ runId: 'r', conversationId: 'chosen', userMessage: 'password=top-secret', lossless: true },+ { runId: 'other', conversationId: 'unrelated', userMessage: 'DO NOT SHARE' }],+ getRunEvents: async () => structuredClone(events),+ getScreenshot: async () => ({ blob: new Blob(['image bytes'], { type: 'image/png' }) }),+ });++ test(`${build}: preparation freezes the session across tab switches, scrubs credentials and preserves screenshots`, async () => {+ const source = await readFile(`src/${build}/src/ui/sidepanel.js`, 'utf8');+ const start = source.indexOf('async function openStoreReviewPrompt()');+ const end = source.indexOf('async function maybePromptStoreReviewAfterSuccess()', start);+ assert.ok(start >= 0 && end > start);+ let capturedTab, resolveSession;+ const panel = vm.createContext({ currentTabId: 71, storeReviewEl: {}, isProcessing: false,+ storeReviewFeedbackEl: { value: 'Previous feedback' }, storeReviewState: {}, storeReviewTraceSource: null,+ sendToBackground: (_action, params) => { capturedTab = params.tabId; return new Promise(resolve => { resolveSession = resolve; }); },+ setStoreReviewStarPreview: () => {}, showStoreReviewStep: () => {}, applyDOMTranslations: () => {},+ markPromptShown: state => state, saveStoreReviewState: async () => {},+ });+ vm.runInContext(source.slice(start, end), panel);+ await vm.runInContext('openStoreReviewPrompt()', panel);+ panel.currentTabId = 99;+ resolveSession({ sessionId: 'chosen' });+ const captured = await panel.storeReviewTraceSource;+ assert.equal(capturedTab, 71);+ const store = fixtureStore([{ seq: 1, kind: 'tool', data: { name: 'click_ax', args: { api_key: 'private-key' },+ result: { success: false, errorCode: 'TARGET_NOT_FOUND', authorization: 'Bearer hidden' } } },+ { seq: 2, kind: 'screenshot', data: {} }]);+ // Old traces may contain content without a lossless marker.+ const list = store.listRuns; store.listRuns = async () => (await list()).map(run => ({ ...run, lossless: undefined }));+ const trace = await prepareFeedbackTrace(store, captured.sessionId, 'test');+ assert.equal(trace.traceType, 'full'); assert.equal(trace.runCount, 1); assert.equal(trace.screenshotCount, 1);+ assert.equal(trace.blob, trace.originalBlob);+ const json = await trace.blob.text();+ assert.doesNotMatch(json, /top-secret|private-key|Bearer hidden|DO NOT SHARE/);+ assert.match(json, /TARGET_NOT_FOUND/); assert.match(json, /screenshot_base64/);+ assert.equal(await prepareFeedbackTrace({ ...store, listRuns: async () => [] }, 'chosen'), null);+ });++ test(`${build}: gzip preserves full exports and oversize fallback is explicitly diagnostic`, async () => {+ const events = Array.from({ length: 80 }, (_, index) => ({ seq: index, kind: 'tool', data: {+ name: 'click_ax', result: { content: 'large trace content '.repeat(100), success: false, errorCode: 'CLICK_FAILED' },+ } }));+ const compressed = await prepareFeedbackTrace(fixtureStore(events), 'chosen', 'test', { limit: 6000 });+ assert.match(compressed.filename, /\.json\.gz$/); assert.equal(compressed.traceType, 'full');+ const expanded = JSON.parse(gunzipSync(Buffer.from(await compressed.blob.arrayBuffer())));+ assert.equal(expanded.runs[0].events.length, 80);+ const legacy = fixtureStore(events.map(event => ({ ...event, privateLegacyField: 'PRIVATE LEGACY EVENT' })));+ const listLegacy = legacy.listRuns;+ legacy.listRuns = async () => (await listLegacy()).map(run => ({ ...run, privateLegacyField: 'PRIVATE LEGACY RUN' }));+ const fallback = await prepareFeedbackTrace(legacy, 'chosen', 'test', { limit: 6000, compress: async () => null });+ assert.equal(fallback.traceType, 'diagnostic'); assert.match(fallback.filename, /-diagnostics\.json$/);+ assert.ok(fallback.blob.size < 6000); assert.ok(fallback.originalBlob.size > 6000);+ assert.ok(fallback.omissions.some(note => note.includes('size limit')));+ assert.doesNotMatch(await fallback.blob.text(), /large trace content|top-secret|PRIVATE LEGACY/);+ assert.match(await fallback.blob.text(), /CLICK_FAILED/);+ });++ test(`${build}: exports preserve diagnostic codes without exposing credential code fields`, async () => {+ const events = [+ { seq: 1, kind: 'tool', data: { name: 'fill_ax', args: { code: 'QUOTA', password: 'private-password' },+ result: { code: 'RATE_LIMIT', content: 'large result '.repeat(2000) } } },+ { seq: 2, kind: 'error', data: { code: 'QUOTA', credentials: { code: 'RATE_LIMIT' } } },+ { seq: 3, kind: 'note', data: { note: 'llm_retry', extra: { code: 'RATE_LIMIT', authCode: '654321' } } },+ { seq: 4, kind: 'turn_end', data: { code: 'COST_LIMIT' } },+ { seq: 5, kind: 'error', data: { code: '654321' } },+ { seq: 6, kind: 'note', data: { note: 'llm_retry', extra: { code: '654321' } } },+ ];+ const original = structuredClone(events);+ const check = entry => {+ assert.equal(entry.events[1].data.code, 'QUOTA');+ assert.equal(entry.events[2].data.extra.code, 'RATE_LIMIT');+ assert.equal(entry.events[3].data.code, 'COST_LIMIT');+ assert.equal(entry.events[4].data.code, '[redacted]');+ assert.equal(entry.events[5].data.extra.code, '[redacted]');+ };+ const standalone = sanitizeTraceExport({ run: { lossless: true, code: 'QUOTA' }, events });+ check(standalone);+ assert.equal(standalone.run.code, '[redacted]');+ assert.equal(standalone.events[0].data.args.code, '[redacted]');+ assert.equal(standalone.events[0].data.result.code, '[redacted]');+ assert.equal(standalone.events[1].data.credentials.code, '[redacted]');+ assert.equal(standalone.events[2].data.extra.authCode, '[redacted]');+ for (const lossless of [undefined, false, true]) {+ const store = { listRuns: async () => [{ runId: 'codes', conversationId: 'codes', lossless }],+ getRunEvents: async () => structuredClone(events), getScreenshot: async () => null };+ for (const options of [{}, { limit: 4000, compress: async () => null }]) {+ const trace = await prepareFeedbackTrace(store, 'codes', 'test', options);+ const payload = JSON.parse(await trace.blob.text());+ check(payload.runs[0]);+ assert.doesNotMatch(await trace.originalBlob.text(), /private-password|654321/);+ }+ }+ assert.deepEqual(events, original, 'sanitizing must not mutate the recorded events');+ });++ test(`${build}: cancelling and declining trace consent never opens an upload handoff`, async () => {+ for (const choice of ['cancel', 'without', 'upload']) {+ const calls = [];+ const result = await submitFeedbackWithTrace({+ rating: 2, comment: 'Clicking failed', copy: getFeedbackCopy('en'),+ prepare: async () => { calls.push('prepare'); return { traceType: 'full', runCount: 1, screenshotCount: 1, omissions: [] }; },+ stage: async () => { calls.push('stage'); return { id: 'staged' }; },+ consent: async () => { calls.push('consent'); return choice; },+ discard: async () => calls.push('discard'),+ open: async args => calls.push(args.includeTrace ? 'upload' : 'text-only'),+ });+ assert.equal(result, choice !== 'cancel');+ assert.equal(calls.includes('upload'), choice === 'upload');+ if (choice === 'cancel') assert.deepEqual(calls, ['prepare', 'stage', 'consent', 'discard']);+ if (choice === 'upload') assert.deepEqual(calls, ['prepare', 'stage', 'consent', 'upload']);+ }+ });++ test(`${build}: disabled tracing uses only bounded metadata and preserves explicit recordings`, () => {+ assert.deepEqual(feedbackRecordingPolicy({ losslessTrace: true }), { enabled: true, feedbackOnly: true, lossless: false });+ assert.equal(feedbackRecordingPolicy({ feedbackDiagnosticsEnabled: false }).enabled, false);+ assert.equal(feedbackRecordingPolicy({ tracingEnabled: true, losslessTrace: true }).lossless, true);+ assert.equal(parseConfigImport(JSON.stringify(createConfigExport({ feedbackDiagnosticsEnabled: false }))).settings.feedbackDiagnosticsEnabled, false);+ const now = Date.now();+ const runs = Array.from({ length: 12 }, (_, i) => ({ runId: String(i), startedAt: now - i, status: 'done', feedbackOnly: true, feedbackBytes: 10 }));+ runs.push({ runId: 'explicit', startedAt: 1, status: 'done' }, { runId: 'active', startedAt: now, status: 'running', feedbackOnly: true });+ assert.deepEqual(feedbackRunsToEvict(runs, now), ['10', '11']);+ assert.equal(feedbackRunsToEvict(runs, now + 8 * 86400000).includes('explicit'), false);+ assert.ok(feedbackRunsToEvict(runs.map(run => ({ ...run, feedbackBytes: 1024 * 1024 })), now).length >= 11);+ });++ test(`${build}: handoff rejects wrong origin, repository, tab, subframe, expiry and missing consent`, () => {+ const url = 'https://github.com/webbrain-one/webbrain/issues/new';+ const sender = { frameId: 0, tab: { id: 4 }, url };+ const draft = { authorized: true, destinationTabId: 4, expiresAt: Date.now() + 10000 };+ assert.equal(mayReadFeedbackDraft(draft, sender, url), true);+ for (const bad of ['https://github.com.evil.test/webbrain-one/webbrain/issues/new', 'https://github.com/other/repo/issues/new', 'http://github.com/webbrain-one/webbrain/issues/new']) {+ assert.equal(isFeedbackDestination(bad), false); assert.equal(mayReadFeedbackDraft(draft, sender, bad), false);+ }+ assert.equal(mayReadFeedbackDraft(draft, { ...sender, frameId: 1 }, url), false);+ assert.equal(mayReadFeedbackDraft(draft, { ...sender, tab: { id: 5 } }, url), false);+ assert.equal(mayReadFeedbackDraft({ ...draft, authorized: false }, sender, url), false);+ assert.equal(mayReadFeedbackDraft({ ...draft, expiresAt: 0 }, sender, url), false);+ });++ async function browserFixture(run) {+ const browser = await engine.launch();+ try {+ const context = await browser.newContext();+ const prefix = `https://feedback-fixture.test/${build}/`;+ await context.route('**/*', async route => {+ const url = new URL(route.request().url());+ if (url.hostname !== 'feedback-fixture.test' || !url.pathname.startsWith(`/${build}/`)) return route.abort();+ const relative = url.pathname.slice(build.length + 2);+ if (!relative) return route.fulfill({ contentType: 'text/html', body: '<!doctype html><button id="send">Send feedback</button>' });+ const file = resolve(`src/${build}`, relative);+ if (!file.startsWith(resolve(`src/${build}`) + sep)) return route.abort();+ await route.fulfill({ contentType: file.endsWith('.css') ? 'text/css' : 'text/javascript', body: await readFile(file) });+ });+ const panel = await context.newPage(); await panel.goto(prefix);+ await panel.addStyleTag({ path: `src/${build}/styles/sidepanel.css` });+ await panel.addStyleTag({ path: `src/${build}/src/ui/feedback-consent.css` });+ await panel.evaluate(prefix => {+ const listeners = () => ({ addListener: () => {} });+ globalThis.settings = {};+ globalThis.tabs = new Map(); globalThis.createdTabs = 0; globalThis.injectedTabs = [];+ const api = {+ runtime: { id: 'fixture-extension', getURL: file => prefix + file, getManifest: () => ({ version: 'test' }) },+ storage: { local: { get: async () => settings, set: async value => Object.assign(settings, value) } },+ tabs: {+ onUpdated: listeners(), onRemoved: listeners(),+ create: async ({ url }) => { const tab = { id: ++createdTabs, url }; tabs.set(tab.id, tab); return tab; },+ get: async id => { if (!tabs.has(id)) throw new Error('No tab'); return tabs.get(id); },+ update: async (id, options) => { Object.assign(tabs.get(id), options); return tabs.get(id); },+ remove: async id => tabs.delete(id),+ executeScript: async id => injectedTabs.push(id),+ },+ alarms: { onAlarm: listeners(), create: () => {} },+ };+ if (prefix.includes('/chrome/')) api.scripting = { executeScript: async ({ target }) => injectedTabs.push(target.tabId) };+ globalThis.chrome = globalThis.browser = api;+ }, prefix);+ await run({ context, panel, prefix });+ } finally { await browser.close(); }+ }++ test(`${build}: real IndexedDB recorder retains bounded diagnostics without raw text or screenshot bytes`, async () => browserFixture(async ({ panel }) => {+ const outcome = await panel.evaluate(async () => {+ const trace = await import('./src/trace/recorder.js');+ settings.tracingEnabled = true; settings.losslessTrace = true;+ await trace.startRun({ runId: 'explicit', conversationId: 'explicit-session', userMessage: 'Keep my opted-in trace' });+ await trace.endRun('explicit');+ settings.tracingEnabled = false; // A stale lossless=true must not affect diagnostics.+ for (let i = 0; i < 12; i++) {+ const runId = await trace.startRun({ runId: `auto-${i}`, conversationId: 'diagnostic-session', userMessage: 'PRIVATE USER TEXT' });+ await trace.recordToolCall(runId, 1, { name: 'click_ax', args: { text: 'PRIVATE ARG' }, result: { success: false, error: 'PRIVATE ERROR', errorCode: 'CLICK_FAILED' } });+ await trace.recordScreenshot(runId, 1, 'data:image/png;base64,aW1hZ2U=', 'screenshot marker');+ await trace.endRun(runId, { status: 'failed', finalContent: 'PRIVATE ANSWER' });+ }+ const runs = await trace.listRuns({ limit: 100 });+ const automatic = runs.filter(run => run.feedbackOnly);+ const events = await trace.getRunEvents(automatic[0].runId);+ const shot = await trace.getScreenshot(automatic[0].runId, events.find(event => event.kind === 'screenshot').seq);+ const before = JSON.stringify({ automatic, events });+ for (let i = 0; i < 200; i++) await trace.recordNote(automatic[0].runId, i, 'timing', { context: 'x'.repeat(3000) });+ await trace.flushPendingWrites();+ const capped = await trace.getRun(automatic[0].runId);+ // Screenshot markers must use the same byte budget, despite having no pixels.+ for (let i = 0; i < 200; i++) await trace.recordScreenshot(automatic[0].runId, i, 'data:image/png;base64,aW1hZ2U=', 'marker'.repeat(1000));+ const screenshotCapped = await trace.getRun(automatic[0].runId);+ // Parallel conversations share a single 2 MiB budget, including headers.+ const active = await Promise.all(Array.from({ length: 20 }, (_, i) => trace.startRun({ runId: `parallel-${i}`, conversationId: `parallel-session-${i}` })));+ await Promise.all(active.filter(Boolean).map(runId => trace.recordNote(runId, 1, 'timing', { context: 'x'.repeat(120000) })));+ const boundedRuns = await trace.listRuns({ limit: 100 });+ const totalBytes = boundedRuns.filter(run => run.feedbackOnly).reduce((sum, run) => sum + run.feedbackBytes, 0);+ await trace.pruneFeedbackDiagnostics({ now: Date.now() + 8 * 86400000 });+ const after = await trace.listRuns({ limit: 100 });+ settings.feedbackDiagnosticsEnabled = false;+ return { count: automatic.length, before, shot, capped, screenshotCapped, totalBytes, after, disabled: await trace.startRun({ runId: 'disabled' }) };+ });+ assert.equal(outcome.count, 10); assert.equal(outcome.shot, undefined);+ assert.doesNotMatch(outcome.before, /PRIVATE/); assert.match(outcome.before, /CLICK_FAILED/);+ assert.equal(outcome.capped.feedbackEventsOmitted, true); assert.ok(outcome.capped.feedbackBytes <= 128 * 1024);+ assert.ok(outcome.screenshotCapped.feedbackBytes <= 128 * 1024);+ assert.ok(outcome.totalBytes <= 2 * 1024 * 1024);+ assert.deepEqual(outcome.after.map(run => run.runId), ['explicit']); assert.equal(outcome.disabled, null);+ }));++ test(`${build}: an evicted completed run still returns its workflow capture`, async () => browserFixture(async ({ panel }) => {+ const outcome = await panel.evaluate(async () => {+ const trace = await import('./src/trace/recorder.js');+ const originalNow = Date.now;+ let clock = originalNow() - 60000;+ Date.now = () => clock;+ try {+ await trace.startRun({ runId: 'slow', conversationId: 'slow-session' });+ await trace.recordToolCall('slow', 1, { name: 'click_ax', args: { id: 'slow-target' }, result: { success: true } });+ for (let i = 0; i < 10; i++) {+ clock += 1000;+ await trace.startRun({ runId: `fast-${i}`, conversationId: `fast-session-${i}` });+ await trace.endRun(`fast-${i}`);+ }+ const workflow = await trace.endRun('slow');+ return { workflow, evicted: await trace.getRun('slow') === undefined,+ retained: (await trace.listRuns()).length, released: await trace.endRun('slow') === null };+ } finally { Date.now = originalNow; }+ });+ assert.equal(outcome.evicted, true); assert.equal(outcome.retained, 10);+ assert.equal(outcome.workflow?.run.runId, 'slow'); assert.equal(outcome.workflow?.run.status, 'done');+ assert.equal(outcome.workflow?.events[0].data.args.id, 'slow-target');+ assert.equal(outcome.released, true);+ }));++ test(`${build}: consent dialog, staged handoff, native attachment, restart recovery and cleanup`, async () => browserFixture(async ({ context, panel, prefix }) => {+ await panel.evaluate(async () => {+ const { createFeedbackHandoff } = await import('./src/feedback-handoff.js');+ const { prepareFeedbackTrace } = await import('./src/trace/feedback-export.js');+ const { stageFeedbackTrace, deleteFeedbackDraft, listFeedbackDrafts, putFeedbackDraft, sweepFeedbackDrafts } = await import('./src/feedback-store.js');+ const { getFeedbackCopy } = await import('./src/ui/feedback-copy.js');+ const { requestFeedbackConsent, submitFeedbackWithTrace } = await import('./src/ui/feedback-consent.js');+ const copy = getFeedbackCopy('en');+ globalThis.controller = createFeedbackHandoff(chrome);+ globalThis.localViews = 0;+ globalThis.prepared = await prepareFeedbackTrace({ listRuns: async () => [{ runId: 'r', conversationId: 'frozen-session', lossless: true }],+ getRunEvents: async () => [{ seq: 1, kind: 'tool', data: { name: 'click_ax', result: { errorCode: 'CLICK_FAILED', password: 'hidden-secret' } } }],+ getScreenshot: async () => null }, 'frozen-session', 'test');+ globalThis.start = () => submitFeedbackWithTrace({+ rating: 2, comment: 'Clicking failed', copy,+ prepare: async () => prepared,+ stage: stageFeedbackTrace, discard: deleteFeedbackDraft,+ consent: (trace, record) => requestFeedbackConsent(trace, copy, async () => {+ localViews += 1;+ const rows = await listFeedbackDrafts();+ if (!rows.find(row => row.id === record.id && !row.authorized)) throw new Error('View must be local before consent');+ }),+ open: params => controller.handle({ action: 'feedback_open', ...params }, { id: chrome.runtime.id, url: chrome.runtime.getURL('src/ui/sidepanel.html') }),+ }).then(result => globalThis.flowResult = result);+ globalThis.store = { listFeedbackDrafts, putFeedbackDraft, sweepFeedbackDrafts };+ });+ await panel.evaluate(() => { void start(); });+ await panel.locator('dialog').waitFor({ state: 'visible' });+ assert.equal(await panel.evaluate(() => createdTabs), 0);+ await panel.getByRole('button', { name: 'View trace', exact: true }).click();+ assert.equal(await panel.evaluate(() => localViews), 1); assert.equal(await panel.evaluate(() => createdTabs), 0);+ await panel.getByRole('button', { name: 'Cancel', exact: true }).click();+ await panel.waitForFunction(() => globalThis.flowResult === false);+ assert.equal(await panel.evaluate(async () => (await store.listFeedbackDrafts()).length), 0);+ await panel.evaluate(() => { flowResult = undefined; void start(); });+ await panel.locator('dialog').waitFor({ state: 'visible' });+ await mkdir('build/feedback-tests', { recursive: true });+ await panel.screenshot({ path: `build/feedback-tests/${build}-consent.png` });+ await panel.getByRole('button', { name: 'Upload trace and open GitHub', exact: true }).click();+ await panel.waitForFunction(() => globalThis.flowResult === true);+ const tab = await panel.evaluate(() => [...tabs.values()][0]);+ const reauthorized = await panel.evaluate(async () => {+ const record = (await store.listFeedbackDrafts())[0];+ try { await controller.handle({ action: 'feedback_open', id: record.id, includeTrace: true, rating: 2 }, { id: chrome.runtime.id, url: chrome.runtime.getURL('src/ui/sidepanel.html') }); return true; }+ catch { return false; }+ });+ assert.equal(reauthorized, false, 'an already authorized draft must be prepared and confirmed again');+ assert.match(tab.url, /github\.com\/webbrain-one\/webbrain\/issues\/new/);+ const initialBody = new URL(tab.url).searchParams.get('body');+ const github = await context.newPage();+ await github.route('https://github.com/**', route => route.fulfill({ contentType: 'text/html', body: `<!doctype html><main><form><textarea id="issue_body"></textarea><input type="file"><button type="button" id="submit">Submit new issue</button></form></main>` }));+ await github.goto(tab.url);+ await github.exposeFunction('handoff', msg => panel.evaluate(({ msg, tab }) => controller.handle(msg, { id: chrome.runtime.id, url: tab.url, frameId: 0, tab }), { msg, tab }));+ await github.evaluate(initialBody => {+ document.querySelector('textarea').value = initialBody;+ globalThis.uploads = 0; globalThis.submissions = 0;+ document.querySelector('#submit').addEventListener('click', () => submissions++);+ document.querySelector('input').addEventListener('change', async event => {+ uploads += 1;+ const file = event.target.files[0]; globalThis.uploadedText = await file.text();+ document.querySelector('textarea').value += `\n[${file.name}](https://github.com/user-attachments/files/123/${file.name})`;+ });+ globalThis.chrome = { runtime: { sendMessage: handoff } };+ }, initialBody);+ const content = await readFile(`src/${build}/src/content/feedback-attachment.js`, 'utf8');+ await github.addScriptTag({ content });+ await github.waitForFunction(() => document.body.textContent.includes('Trace attached.'));+ assert.equal(await github.evaluate(() => uploads), 1);+ assert.equal(await github.evaluate(() => submissions), 0);+ assert.doesNotMatch(await github.evaluate(() => uploadedText), /hidden-secret/);+ assert.match(await github.locator('textarea').inputValue(), /Clicking failed/);+ await github.addScriptTag({ content }); assert.equal(await github.evaluate(() => uploads), 1);+ assert.equal(await panel.evaluate(async () => (await store.listFeedbackDrafts()).length), 0);++ // Recreate a staged, authorized draft in an interrupted upload state.+ const retry = await panel.evaluate(async tab => {+ const { stageFeedbackTrace } = await import('./src/feedback-store.js');+ const record = await stageFeedbackTrace(prepared);+ record.authorized = true; record.includeTrace = true; record.destinationTabId = tab.id;+ record.body = 'Original feedback'; record.initialBody = ''; record.status = 'pending';+ await store.putFeedbackDraft(record); return { id: record.id, token: record.token };+ }, tab);+ const wrongToken = await panel.evaluate(async ({ tab, retry }) => {+ try { await controller.handle({ action: 'feedback_chunk', id: retry.id, token: 'wrong', offset: 0 }, { id: chrome.runtime.id, url: tab.url, frameId: 0, tab }); return false; } catch { return true; }+ }, { tab, retry }); assert.equal(wrongToken, true);+ const dispatches = await panel.evaluate(async ({ tab, retry }) => {+ const msg = { action: 'feedback_upload_started', ...retry };+ const sender = { id: chrome.runtime.id, url: tab.url, frameId: 0, tab };+ return (await Promise.allSettled([controller.handle(msg, sender), controller.handle(msg, sender)])).map(result => result.status);+ }, { tab, retry });+ assert.deepEqual(dispatches.sort(), ['fulfilled', 'rejected']);+ await github.reload();+ await github.evaluate(() => {+ document.querySelector('textarea').value = 'User edits must survive'; globalThis.uploads = 0;+ document.querySelector('input').addEventListener('change', event => {+ uploads++; const file = event.target.files[0];+ document.querySelector('textarea').value += `\n[${file.name}](https://github.com/user-attachments/files/123/${file.name})`;+ });+ globalThis.chrome = { runtime: { sendMessage: handoff } };+ });+ await github.addScriptTag({ content });+ await github.getByRole('button', { name: 'Retry attachment', exact: true }).waitFor({ state: 'visible' });+ assert.equal(await github.evaluate(() => uploads), 0);+ await github.getByRole('button', { name: 'Retry attachment', exact: true }).click();+ await github.waitForFunction(() => document.body.textContent.includes('Trace attached.'));+ assert.equal(await github.evaluate(() => uploads), 1);+ assert.match(await github.locator('textarea').inputValue(), /^User edits must survive/);+ await panel.evaluate(async () => {+ const { stageFeedbackTrace } = await import('./src/feedback-store.js');+ const record = await stageFeedbackTrace(prepared);+ record.expiresAt = 0; await store.putFeedbackDraft(record); await store.sweepFeedbackDrafts();+ });+ assert.equal(await panel.evaluate(async () => (await store.listFeedbackDrafts()).length), 0);+ }));+}++test('Chrome unpacked extension: worker flush, consent, login return and isolated native upload', async () => {+ await mkdir('build/feedback-tests', { recursive: true });+ // A fresh profile avoids Chromium's persisted extension-module cache.+ const profile = await mkdtemp(resolve('build/feedback-tests/extension-'));+ const extension = resolve('src/chrome');+ const context = await chromium.launchPersistentContext(profile, {+ headless: true, channel: 'chromium',+ args: [`--disable-extensions-except=${extension}`, `--load-extension=${extension}`],+ });+ try {+ let loggedIn = false, uploads = 0, uploadedText = '';+ await context.exposeFunction('recordFeedbackUpload', text => { uploads++; uploadedText = text; });+ await context.route('https://github.com/**', async route => {+ const url = new URL(route.request().url());+ if (url.pathname === '/login') return route.fulfill({ contentType: 'text/html', body:+ `<!doctype html><a href="${url.searchParams.get('return_to')}">Return to feedback</a>` });+ if (!loggedIn) {+ loggedIn = true;+ // Playwright routes only the first request in an HTTP redirect chain.+ // Navigate from the fixture so the login document is intercepted too.+ return route.fulfill({ contentType: 'text/html', body: `<script>location.replace(${JSON.stringify(`https://github.com/login?return_to=${encodeURIComponent(url.href)}`)})</script>` });+ }+ return route.fulfill({ contentType: 'text/html', body: `<!doctype html><main><form>+ <textarea id="issue_body"></textarea><input type="file"><button type="button">Submit new issue</button></form></main>+ <script>+ document.querySelector('textarea').value = new URL(location.href).searchParams.get('body') || '';+ document.querySelector('input').addEventListener('change', async event => {+ const file = event.target.files[0]; await recordFeedbackUpload(await file.text());+ document.querySelector('textarea').value += '\\n[' + file.name + '](https://github.com/user-attachments/files/123/' + file.name + ')';+ });+ </script>` });+ });+ const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker');+ const origin = `chrome-extension://${new URL(worker.url()).hostname}`;+ const panel = await context.newPage();+ await panel.goto(`${origin}/src/ui/sidepanel.html`);+ const flush = await panel.evaluate(() => chrome.runtime.sendMessage({ target: 'background', action: 'feedback_flush' }));+ assert.equal(flush.ok, true, flush.error);+ await panel.evaluate(async () => {+ const { prepareFeedbackTrace } = await import('../trace/feedback-export.js');+ const { stageFeedbackTrace, deleteFeedbackDraft } = await import('../feedback-store.js');+ const { submitFeedbackWithTrace, requestFeedbackConsent } = await import('./feedback-consent.js');+ const { getFeedbackCopy } = await import('./feedback-copy.js');+ const copy = getFeedbackCopy('en');+ const prepared = await prepareFeedbackTrace({+ listRuns: async () => [{ runId: 'native', conversationId: 'native-session', lossless: true }],+ getRunEvents: async () => [{ seq: 1, kind: 'tool', data: { name: 'click_ax', result: { password: 'NATIVE SECRET', success: false } } }],+ getScreenshot: async () => null,+ }, 'native-session');+ void submitFeedbackWithTrace({ rating: 2, comment: 'Native extension feedback', copy,+ prepare: async () => prepared, stage: stageFeedbackTrace, discard: deleteFeedbackDraft,+ consent: trace => requestFeedbackConsent(trace, copy, async () => {}),+ open: async params => {+ const result = await chrome.runtime.sendMessage({ target: 'background', action: 'feedback_open', ...params });+ if (!result.ok) throw new Error(result.error);+ },+ }).then(result => globalThis.feedbackResult = result).catch(error => globalThis.feedbackError = error.message);+ });+ await panel.locator('dialog.feedback-trace-dialog').waitFor({ state: 'visible' });+ assert.equal(uploads, 0);+ assert.equal(context.pages().some(page => page.url().startsWith('https://github.com/')), false);+ const githubOpened = context.waitForEvent('page');+ await panel.getByRole('button', { name: 'Upload trace and open GitHub', exact: true }).click();+ await panel.waitForFunction(() => feedbackResult === true || globalThis.feedbackError);+ assert.equal(await panel.evaluate(() => globalThis.feedbackError), undefined);+ const github = await githubOpened;+ await github.getByRole('link', { name: 'Return to feedback' }).waitFor({ state: 'visible' });+ assert.equal(uploads, 0, 'login must not receive trace bytes');+ const cdp = await context.browser().newBrowserCDPSession();+ const targets = await cdp.send('Target.getTargets');+ const workerTarget = targets.targetInfos.find(target => target.type === 'service_worker' && target.url.startsWith(origin));+ assert.ok(workerTarget);+ await cdp.send('Target.closeTarget', { targetId: workerTarget.targetId });+ await cdp.detach();+ await github.getByRole('link', { name: 'Return to feedback' }).click();+ await github.getByText('Trace attached. Review and submit your feedback on GitHub.', { exact: true }).waitFor();+ assert.equal(uploads, 1); assert.doesNotMatch(uploadedText, /NATIVE SECRET/);+ assert.match(await github.locator('textarea').inputValue(), /Native extension feedback/);+ assert.equal(await panel.evaluate(async () => (await (await import('../feedback-store.js')).listFeedbackDrafts()).length), 0);+ // Closing a destination also clears abandoned temporary exports.+ await panel.evaluate(async () => {+ const store = await import('../feedback-store.js');+ const [tab] = await chrome.tabs.query({ url: 'https://github.com/webbrain-one/webbrain/issues/new*' });+ await store.putFeedbackDraft({ id: 'closing-tab', destinationTabId: tab.id, authorized: false, expiresAt: Date.now() + 3600000 });+ });+ await github.close();+ await panel.waitForFunction(async () => (await (await import('../feedback-store.js')).listFeedbackDrafts()).length === 0);+ const settings = await context.newPage();+ await settings.goto(`${origin}/src/ui/settings.html`);+ const cleared = await settings.evaluate(() => chrome.runtime.sendMessage({ target: 'background', action: 'feedback_clear_diagnostics' }));+ assert.equal(cleared.ok, true, cleared.error);+ } finally { await context.close(); }+});diff --git a/test/run.js b/test/run.jsindex 7b0df2eb7..b24d181d2 100644--- a/test/run.js+++ b/test/run.js@@ -15227,8 +15227,8 @@ test('trace lossless tier: runtime-config accepts the boolean and defaults staytest('trace lossless tier: recorder branches on the tier and clamps payloads', () => {for (const browser of ['chrome', 'firefox']) {const recorderSource = fs.readFileSync(path.join(ROOT, `src/${browser}/src/trace/recorder.js`), 'utf8');- assert.match(recorderSource, /async function losslessTraceEnabled\(\)/, `${browser}: losslessTraceEnabled missing`);- assert.match(recorderSource, /const lossless = meta\.lossless === true \|\| await losslessTraceEnabled\(\);/, `${browser}: tier decision missing in startRun`);+ assert.match(recorderSource, /feedbackRecordingPolicy\(settings, meta\.force === true\)/, `${browser}: recording policy missing`);+ assert.match(recorderSource, /const lossless = !policy\.feedbackOnly && \(meta\.lossless === true \|\| policy\.lossless\);/, `${browser}: tier decision must exclude automatic diagnostics`);assert.match(recorderSource, /\.\.\.\(lossless \? \{ lossless: true, losslessBytes: 0, losslessBytesEncoding: 'utf8' \} : \{\}\)/, `${browser}: run record does not stamp the tier and UTF-8 accounting unit`);assert.match(recorderSource, /const LOSSILESS_RESULT_CAP = 200_000;/, `${browser}: lossless result cap missing`);assert.match(recorderSource, /const LOSSILESS_REQUEST_CAP = 500_000;/, `${browser}: lossless request cap missing`);@@ -27003,11 +27003,12 @@ test('cloud runs force trace capture without changing the interactive opt-in def'utf8',);assert.match(agentSource, /force:\s*runOptions\?\.cloudRun === true/);- assert.match(recorderSource, /if \(!forced && !\(await tracingEnabled\(\)\)\) return null/);+ assert.match(recorderSource, /feedbackRecordingPolicy\(settings, meta\.force === true\)/);+ assert.match(recorderSource, /if \(!policy\.enabled\) return null/);assert.match(recorderSource, /tracingEnabledForRun\(runId\)/);// The forced flag is restored from the durable run record after SW eviction// (peekRunFlags), keeping forced-capture semantics without an in-memory map.- assert.match(recorderSource, /forced: flags\.forced, lossless: flags\.lossless/);+ assert.match(recorderSource, /forced: flags\.forced,[^\n]*lossless: flags\.lossless/);});test('cloud trace keeps CAPTCHA frame/vendor diagnostics after the rolling update window drops the event', async () => {