Skip to content

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

Show the auto-timeout as a clock ring that empties in the card's bottom-right corner

Claude9a85b5b5e6e8
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 6fd69d671..814c9375b 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -22134,7 +22134,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
});
if (typeof onUpdate === 'function') {
try {
- onUpdate('plan_review', { planId, plan, markdown, verboseMarkdown });
+ // The panel shows how long is left before the plan runs on its own.
+ onUpdate('plan_review', {
+ planId, plan, markdown, verboseMarkdown,
+ timeoutSec: Math.round(PLAN_REVIEW_TIMEOUT_MS / 1000),
+ deadlineTs: Date.now() + PLAN_REVIEW_TIMEOUT_MS,
+ });
} catch {}
}
try {
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index f293ca545..33c967dd7 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -9,6 +9,7 @@ import { appendGeneratedMedia, restoreGeneratedMedia } from './generated-media-v
*/
import { createQuotaController } from './compass-quota.js';
+import { createTimeoutRing, updateTimeoutRing } from './timeout-ring.js';
import { reportSidePanelPresence } from '../sidepanel-presence.js';
import { t, getLocale, setLocale, LANGUAGES, applyDOMTranslations, translationsForKey } from './i18n.js';
import { CAPABILITY_LABEL } from '../agent/permission-gate.js';
@@ -7234,10 +7235,44 @@ function planReviewViewNeedsHydration(view, savedText = '') {
|| String(savedText || '') !== '';
}
+// The plan runs on its own when the review times out. A clock ring at the end of the action row
+// empties over that time; it is rebuilt on a restored card and removed once the review is settled.
+function stopPlanReviewTimeoutRing(card) {
+ if (!card) return;
+ if (card._planReviewRingTimer) {
+ try { clearInterval(card._planReviewRingTimer); } catch {}
+ card._planReviewRingTimer = null;
+ }
+ card.querySelectorAll('.plan-review-actions .timeout-ring').forEach((ring) => ring.remove());
+}
+
+function startPlanReviewTimeoutRing(card) {
+ stopPlanReviewTimeoutRing(card);
+ const deadlineTs = Number(card?.dataset?.deadlineTs);
+ const actions = card?.querySelector?.('.plan-review-actions');
+ if (!actions || !Number.isFinite(deadlineTs) || deadlineTs <= 0) return;
+ const totalMs = Math.max((Number(card.dataset.timeoutSec) || 0) * 1000, deadlineTs - Date.now());
+ if (deadlineTs - Date.now() <= 0 || totalMs <= 0) return;
+ const ring = createTimeoutRing();
+ actions.appendChild(ring);
+ const tick = () => {
+ const remainingMs = deadlineTs - Date.now();
+ if (!card.isConnected || card.classList.contains('plan-reviewed') || remainingMs <= 0) {
+ stopPlanReviewTimeoutRing(card);
+ return;
+ }
+ updateTimeoutRing(ring, remainingMs, totalMs);
+ };
+ // The card is not in the document yet when it is first built, so only the interval checks that.
+ updateTimeoutRing(ring, deadlineTs - Date.now(), totalMs);
+ card._planReviewRingTimer = setInterval(tick, 250);
+}
+
function bindPlanReviewCard(card) {
if (!card || card.classList.contains('plan-reviewed')) return;
const planId = String(card.dataset.planId || '');
if (!planId) return;
+ startPlanReviewTimeoutRing(card);
const rawTabId = card.dataset.tabId;
const tabId = rawTabId != null && rawTabId !== '' ? Number(rawTabId) : currentTabId;
if (tabId == null || Number.isNaN(tabId)) return;
@@ -11749,9 +11784,18 @@ function startClarifyCountdown(card, { tabId, clarifyId, deadlineTs, firstOption
if (!card || !deadlineTs || deadlineTs <= 0) return;
clearClarifyCountdown(card);
+ // The label says what the timeout does; the ring in the corner shows how much time is left.
const timerEl = document.createElement('div');
timerEl.className = 'clarify-timeout';
+ const labelEl = document.createElement('span');
+ labelEl.className = 'clarify-timeout-label';
+ const ringEl = createTimeoutRing();
+ timerEl.append(labelEl, ringEl);
card.appendChild(timerEl);
+ // The full period (typing renews the deadline to a whole period again); a restored card without
+ // it falls back to what was left when the countdown started.
+ const configuredTotalMs = (Number(card.dataset.timeoutSec) || 0) * 1000;
+ const totalMs = Math.max(configuredTotalMs, Math.max(0, (Number(card.dataset.deadlineTs) || deadlineTs) - Date.now()));
const tick = () => {
if (card.classList.contains('clarify-answered')) {
@@ -11769,7 +11813,8 @@ function startClarifyCountdown(card, { tabId, clarifyId, deadlineTs, firstOption
// localized label; the countdown names the label.
const namedButton = continues ? null : Array.from(card.querySelectorAll('.clarify-option'))
.find(button => button.textContent === timeoutAnswer || (!!button.dataset.value && button.dataset.value === timeoutAnswer));
- timerEl.textContent = typeof t === 'function'
+ updateTimeoutRing(ringEl, remainingMs, totalMs);
+ labelEl.textContent = typeof t === 'function'
? (continues
? t('sp.clarify.auto_timeout_continue', { seconds: remainingSec })
: namedButton
@@ -11936,6 +11981,12 @@ function renderPlanReviewCard(data) {
if (data.requestId) card.dataset.runRequestId = String(data.requestId);
if (data.runId) card.dataset.runId = String(data.runId);
card.dataset.editing = 'false';
+ const planTimeoutSec = Number(data.timeoutSec);
+ const planDeadlineTs = Number(data.deadlineTs);
+ if (Number.isFinite(planTimeoutSec) && planTimeoutSec > 0 && Number.isFinite(planDeadlineTs) && planDeadlineTs > 0) {
+ card.dataset.timeoutSec = String(Math.floor(planTimeoutSec));
+ card.dataset.deadlineTs = String(Math.floor(planDeadlineTs));
+ }
const header = document.createElement('div');
header.className = 'plan-review-header';
diff --git a/src/chrome/src/ui/timeout-ring.js b/src/chrome/src/ui/timeout-ring.js
new file mode 100644
index 000000000..f9a5034fd
--- /dev/null
+++ b/src/chrome/src/ui/timeout-ring.js
@@ -0,0 +1,55 @@
+// A small clock face that empties as an auto-timeout runs down: a ring that
+// shrinks clockwise with a hand sweeping the removed part. It carries no text
+// (the label next to it says what happens), so it needs no translation.
+const SVG_NS = 'http://www.w3.org/2000/svg';
+const RADIUS = 9;
+export const TIMEOUT_RING_CIRCUMFERENCE = 2 * Math.PI * RADIUS;
+// Below this share of the time (or this many seconds) the ring turns to the warning color.
+const LOW_SHARE = 0.2;
+const LOW_MS = 10_000;
+
+function svgEl(name, attrs = {}) {
+ const el = document.createElementNS(SVG_NS, name);
+ for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
+ return el;
+}
+
+export function createTimeoutRing() {
+ const ring = document.createElement('span');
+ ring.className = 'timeout-ring';
+ ring.setAttribute('aria-hidden', 'true');
+ const svg = svgEl('svg', { viewBox: '0 0 24 24', width: 22, height: 22 });
+ svg.append(
+ svgEl('circle', { class: 'timeout-ring-track', cx: 12, cy: 12, r: RADIUS, fill: 'none', 'stroke-width': 3 }),
+ svgEl('circle', {
+ class: 'timeout-ring-progress', cx: 12, cy: 12, r: RADIUS, fill: 'none', 'stroke-width': 3, 'stroke-linecap': 'round',
+ 'stroke-dasharray': TIMEOUT_RING_CIRCUMFERENCE.toFixed(3), 'stroke-dashoffset': 0, transform: 'rotate(-90 12 12)',
+ }),
+ svgEl('line', { class: 'timeout-ring-hand', x1: 12, y1: 12, x2: 12, y2: 7, 'stroke-width': 2, 'stroke-linecap': 'round' }),
+ );
+ ring.appendChild(svg);
+ return ring;
+}
+
+export function timeoutRingShare(remainingMs, totalMs) {
+ const total = Number(totalMs);
+ const remaining = Number(remainingMs);
+ if (!Number.isFinite(total) || total <= 0 || !Number.isFinite(remaining)) return 0;
+ return Math.max(0, Math.min(1, remaining / total));
+}
+
+export function formatTimeoutRingTime(remainingMs) {
+ const seconds = Math.max(0, Math.ceil(Number(remainingMs) / 1000) || 0);
+ return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
+}
+
+export function updateTimeoutRing(ring, remainingMs, totalMs) {
+ if (!ring) return;
+ const share = timeoutRingShare(remainingMs, totalMs);
+ const progress = ring.querySelector('.timeout-ring-progress');
+ const hand = ring.querySelector('.timeout-ring-hand');
+ if (progress) progress.setAttribute('stroke-dashoffset', (TIMEOUT_RING_CIRCUMFERENCE * (1 - share)).toFixed(3));
+ if (hand) hand.setAttribute('transform', `rotate(${((1 - share) * 360).toFixed(1)} 12 12)`);
+ ring.classList.toggle('timeout-ring-low', share <= LOW_SHARE || Number(remainingMs) <= LOW_MS);
+ ring.title = formatTimeoutRingTime(remainingMs);
+}
diff --git a/src/chrome/styles/sidepanel.css b/src/chrome/styles/sidepanel.css
index e2a69f3bd..c8bbaece3 100644
--- a/src/chrome/styles/sidepanel.css
+++ b/src/chrome/styles/sidepanel.css
@@ -4546,11 +4546,52 @@ html[data-ui-scale="175"] .composer-toolbar .provider-picker {
}
.clarify-timeout {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
font-size: 11px;
color: var(--text-secondary);
font-variant-numeric: tabular-nums;
}
+/* The clock ring that empties with an auto-timeout: bottom-right of the clarification and plan
+ review cards. */
+.timeout-ring {
+ flex: 0 0 auto;
+ display: inline-flex;
+ margin-inline-start: auto;
+ color: var(--accent);
+ cursor: default;
+}
+
+.timeout-ring svg { display: block; }
+
+.timeout-ring-track {
+ stroke: var(--border);
+}
+
+.timeout-ring-progress,
+.timeout-ring-hand {
+ stroke: currentColor;
+}
+
+.timeout-ring-progress {
+ transition: stroke-dashoffset 0.25s linear, stroke 0.2s;
+}
+
+.timeout-ring-low {
+ color: var(--warning);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .timeout-ring-progress { transition: none; }
+}
+
+.plan-review-actions {
+ align-items: center;
+}
+
/* ─── Planner gate (issue #165) ───────────────────────────────────── */
.plan-review-card {
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 026cf1da4..0d31ed493 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -19200,7 +19200,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
});
if (typeof onUpdate === 'function') {
try {
- onUpdate('plan_review', { planId, plan, markdown, verboseMarkdown });
+ // The panel shows how long is left before the plan runs on its own.
+ onUpdate('plan_review', {
+ planId, plan, markdown, verboseMarkdown,
+ timeoutSec: Math.round(PLAN_REVIEW_TIMEOUT_MS / 1000),
+ deadlineTs: Date.now() + PLAN_REVIEW_TIMEOUT_MS,
+ });
} catch {}
}
try {
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 42c40b3b1..01be9bbda 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -9,6 +9,7 @@ import { saveScreenshot } from './screenshot-download.js';
*/
import { createQuotaController } from './compass-quota.js';
+import { createTimeoutRing, updateTimeoutRing } from './timeout-ring.js';
import { t, getLocale, setLocale, LANGUAGES, applyDOMTranslations, translationsForKey } from './i18n.js';
import { CAPABILITY_LABEL } from '../agent/permission-gate.js';
import { sanitizeMarkdownLinks } from './markdown-link.js';
@@ -7069,10 +7070,44 @@ function planReviewViewNeedsHydration(view, savedText = '') {
|| String(savedText || '') !== '';
}
+// The plan runs on its own when the review times out. A clock ring at the end of the action row
+// empties over that time; it is rebuilt on a restored card and removed once the review is settled.
+function stopPlanReviewTimeoutRing(card) {
+ if (!card) return;
+ if (card._planReviewRingTimer) {
+ try { clearInterval(card._planReviewRingTimer); } catch {}
+ card._planReviewRingTimer = null;
+ }
+ card.querySelectorAll('.plan-review-actions .timeout-ring').forEach((ring) => ring.remove());
+}
+
+function startPlanReviewTimeoutRing(card) {
+ stopPlanReviewTimeoutRing(card);
+ const deadlineTs = Number(card?.dataset?.deadlineTs);
+ const actions = card?.querySelector?.('.plan-review-actions');
+ if (!actions || !Number.isFinite(deadlineTs) || deadlineTs <= 0) return;
+ const totalMs = Math.max((Number(card.dataset.timeoutSec) || 0) * 1000, deadlineTs - Date.now());
+ if (deadlineTs - Date.now() <= 0 || totalMs <= 0) return;
+ const ring = createTimeoutRing();
+ actions.appendChild(ring);
+ const tick = () => {
+ const remainingMs = deadlineTs - Date.now();
+ if (!card.isConnected || card.classList.contains('plan-reviewed') || remainingMs <= 0) {
+ stopPlanReviewTimeoutRing(card);
+ return;
+ }
+ updateTimeoutRing(ring, remainingMs, totalMs);
+ };
+ // The card is not in the document yet when it is first built, so only the interval checks that.
+ updateTimeoutRing(ring, deadlineTs - Date.now(), totalMs);
+ card._planReviewRingTimer = setInterval(tick, 250);
+}
+
function bindPlanReviewCard(card) {
if (!card || card.classList.contains('plan-reviewed')) return;
const planId = String(card.dataset.planId || '');
if (!planId) return;
+ startPlanReviewTimeoutRing(card);
const rawTabId = card.dataset.tabId;
const tabId = rawTabId != null && rawTabId !== '' ? Number(rawTabId) : currentTabId;
if (tabId == null || Number.isNaN(tabId)) return;
@@ -11247,9 +11282,18 @@ function startClarifyCountdown(card, { tabId, clarifyId, deadlineTs, firstOption
if (!card || !deadlineTs || deadlineTs <= 0) return;
clearClarifyCountdown(card);
+ // The label says what the timeout does; the ring in the corner shows how much time is left.
const timerEl = document.createElement('div');
timerEl.className = 'clarify-timeout';
+ const labelEl = document.createElement('span');
+ labelEl.className = 'clarify-timeout-label';
+ const ringEl = createTimeoutRing();
+ timerEl.append(labelEl, ringEl);
card.appendChild(timerEl);
+ // The full period (typing renews the deadline to a whole period again); a restored card without
+ // it falls back to what was left when the countdown started.
+ const configuredTotalMs = (Number(card.dataset.timeoutSec) || 0) * 1000;
+ const totalMs = Math.max(configuredTotalMs, Math.max(0, (Number(card.dataset.deadlineTs) || deadlineTs) - Date.now()));
const tick = () => {
if (card.classList.contains('clarify-answered')) {
@@ -11267,7 +11311,8 @@ function startClarifyCountdown(card, { tabId, clarifyId, deadlineTs, firstOption
// localized label; the countdown names the label.
const namedButton = continues ? null : Array.from(card.querySelectorAll('.clarify-option'))
.find(button => button.textContent === timeoutAnswer || (!!button.dataset.value && button.dataset.value === timeoutAnswer));
- timerEl.textContent = typeof t === 'function'
+ updateTimeoutRing(ringEl, remainingMs, totalMs);
+ labelEl.textContent = typeof t === 'function'
? (continues
? t('sp.clarify.auto_timeout_continue', { seconds: remainingSec })
: namedButton
@@ -11572,6 +11617,12 @@ function renderPlanReviewCard(data) {
if (data.requestId) card.dataset.runRequestId = String(data.requestId);
if (data.runId) card.dataset.runId = String(data.runId);
card.dataset.editing = 'false';
+ const planTimeoutSec = Number(data.timeoutSec);
+ const planDeadlineTs = Number(data.deadlineTs);
+ if (Number.isFinite(planTimeoutSec) && planTimeoutSec > 0 && Number.isFinite(planDeadlineTs) && planDeadlineTs > 0) {
+ card.dataset.timeoutSec = String(Math.floor(planTimeoutSec));
+ card.dataset.deadlineTs = String(Math.floor(planDeadlineTs));
+ }
const header = document.createElement('div');
header.className = 'plan-review-header';
diff --git a/src/firefox/src/ui/timeout-ring.js b/src/firefox/src/ui/timeout-ring.js
new file mode 100644
index 000000000..f9a5034fd
--- /dev/null
+++ b/src/firefox/src/ui/timeout-ring.js
@@ -0,0 +1,55 @@
+// A small clock face that empties as an auto-timeout runs down: a ring that
+// shrinks clockwise with a hand sweeping the removed part. It carries no text
+// (the label next to it says what happens), so it needs no translation.
+const SVG_NS = 'http://www.w3.org/2000/svg';
+const RADIUS = 9;
+export const TIMEOUT_RING_CIRCUMFERENCE = 2 * Math.PI * RADIUS;
+// Below this share of the time (or this many seconds) the ring turns to the warning color.
+const LOW_SHARE = 0.2;
+const LOW_MS = 10_000;
+
+function svgEl(name, attrs = {}) {
+ const el = document.createElementNS(SVG_NS, name);
+ for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
+ return el;
+}
+
+export function createTimeoutRing() {
+ const ring = document.createElement('span');
+ ring.className = 'timeout-ring';
+ ring.setAttribute('aria-hidden', 'true');
+ const svg = svgEl('svg', { viewBox: '0 0 24 24', width: 22, height: 22 });
+ svg.append(
+ svgEl('circle', { class: 'timeout-ring-track', cx: 12, cy: 12, r: RADIUS, fill: 'none', 'stroke-width': 3 }),
+ svgEl('circle', {
+ class: 'timeout-ring-progress', cx: 12, cy: 12, r: RADIUS, fill: 'none', 'stroke-width': 3, 'stroke-linecap': 'round',
+ 'stroke-dasharray': TIMEOUT_RING_CIRCUMFERENCE.toFixed(3), 'stroke-dashoffset': 0, transform: 'rotate(-90 12 12)',
+ }),
+ svgEl('line', { class: 'timeout-ring-hand', x1: 12, y1: 12, x2: 12, y2: 7, 'stroke-width': 2, 'stroke-linecap': 'round' }),
+ );
+ ring.appendChild(svg);
+ return ring;
+}
+
+export function timeoutRingShare(remainingMs, totalMs) {
+ const total = Number(totalMs);
+ const remaining = Number(remainingMs);
+ if (!Number.isFinite(total) || total <= 0 || !Number.isFinite(remaining)) return 0;
+ return Math.max(0, Math.min(1, remaining / total));
+}
+
+export function formatTimeoutRingTime(remainingMs) {
+ const seconds = Math.max(0, Math.ceil(Number(remainingMs) / 1000) || 0);
+ return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
+}
+
+export function updateTimeoutRing(ring, remainingMs, totalMs) {
+ if (!ring) return;
+ const share = timeoutRingShare(remainingMs, totalMs);
+ const progress = ring.querySelector('.timeout-ring-progress');
+ const hand = ring.querySelector('.timeout-ring-hand');
+ if (progress) progress.setAttribute('stroke-dashoffset', (TIMEOUT_RING_CIRCUMFERENCE * (1 - share)).toFixed(3));
+ if (hand) hand.setAttribute('transform', `rotate(${((1 - share) * 360).toFixed(1)} 12 12)`);
+ ring.classList.toggle('timeout-ring-low', share <= LOW_SHARE || Number(remainingMs) <= LOW_MS);
+ ring.title = formatTimeoutRingTime(remainingMs);
+}
diff --git a/src/firefox/styles/sidepanel.css b/src/firefox/styles/sidepanel.css
index 59edd5825..b4ca2a6fe 100644
--- a/src/firefox/styles/sidepanel.css
+++ b/src/firefox/styles/sidepanel.css
@@ -4385,11 +4385,52 @@ html[data-ui-scale="175"] .composer-toolbar .provider-picker {
}
.clarify-timeout {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
font-size: 11px;
color: var(--text-secondary);
font-variant-numeric: tabular-nums;
}
+/* The clock ring that empties with an auto-timeout: bottom-right of the clarification and plan
+ review cards. */
+.timeout-ring {
+ flex: 0 0 auto;
+ display: inline-flex;
+ margin-inline-start: auto;
+ color: var(--accent);
+ cursor: default;
+}
+
+.timeout-ring svg { display: block; }
+
+.timeout-ring-track {
+ stroke: var(--border);
+}
+
+.timeout-ring-progress,
+.timeout-ring-hand {
+ stroke: currentColor;
+}
+
+.timeout-ring-progress {
+ transition: stroke-dashoffset 0.25s linear, stroke 0.2s;
+}
+
+.timeout-ring-low {
+ color: var(--warning);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .timeout-ring-progress { transition: none; }
+}
+
+.plan-review-actions {
+ align-items: center;
+}
+
/* ─── Planner gate (issue #165) ───────────────────────────────────── */
.plan-review-card {
diff --git a/test/clarify-timeout-policy.mjs b/test/clarify-timeout-policy.mjs
index a610e401a..7c300dda9 100644
--- a/test/clarify-timeout-policy.mjs
+++ b/test/clarify-timeout-policy.mjs
@@ -353,6 +353,9 @@ let browser;
before(async () => { browser = await chromium.launch({ headless: true }); });
after(async () => { await browser?.close(); });
+// The countdown draws its clock ring with the shared module; the page harness has no module loader.
+const ringSource = async (build) => (await read(`src/${build}/src/ui/timeout-ring.js`)).replace(/^export /gm, '');
+
function extract(source, name) {
source = source.replace(/\r\n/g, '\n');
const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
@@ -373,6 +376,7 @@ for (const build of ['chrome', 'firefox']) {
function t(key, params = {}) { return String(EN[key] || key).replace(/\\{(\\w+)\\}/g, (_, k) => params[k] ?? ''); }
window.submitted = [];
function submitClarify(card, tabId, clarifyId, answer, source) { window.submitted.push({ answer, source }); }
+ ${await ringSource(build)}
${extract(panel, 'clearClarifyCountdown')}
${extract(panel, 'startClarifyCountdown')}
window.makeCard = (options, timeoutAnswer, continues) => {
diff --git a/test/guard-ask-cards.mjs b/test/guard-ask-cards.mjs
index ae1451b57..5a977500f 100644
--- a/test/guard-ask-cards.mjs
+++ b/test/guard-ask-cards.mjs
@@ -1201,6 +1201,8 @@ let chromiumBrowser;
before(async () => { chromiumBrowser = await chromium.launch({ headless: true }); });
after(async () => { await chromiumBrowser?.close(); });
+const ringSource = async (build) => (await read(`src/${build}/src/ui/timeout-ring.js`)).replace(/^export /gm, '');
+
function extract(source, name) {
source = source.replace(/\r\n/g, '\n');
const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
@@ -1233,6 +1235,7 @@ async function panel(build, locale = 'en') {
async function sendToBackground(action, payload) { sent.push([action, payload]); return { matched: true }; }
${extract(source, 'renderClarifyCard')}
${extract(source, 'submitClarify')}
+ ${await ringSource(build)}
${extract(source, 'clearClarifyCountdown')}
${extract(source, 'startClarifyCountdown')}
${extract(source, 'lockClarifyCardFromAuto')}
diff --git a/test/timeout-ring.mjs b/test/timeout-ring.mjs
new file mode 100644
index 000000000..b31504153
--- /dev/null
+++ b/test/timeout-ring.mjs
@@ -0,0 +1,178 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import { after, before, describe, test } from 'node:test';
+import { chromium } from 'playwright';
+
+const read = async (rel) => (await fs.readFile(new URL(`../${rel}`, import.meta.url), 'utf8')).replace(/\r\n/g, '\n');
+const extract = (source, name) => {
+ const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
+ assert.ok(start >= 0, name);
+ return source.slice(start, source.indexOf('\n}', start) + 2);
+};
+
+test('the ring module is identical in both builds', async () => {
+ assert.equal(await read('src/chrome/src/ui/timeout-ring.js'), await read('src/firefox/src/ui/timeout-ring.js'));
+});
+
+for (const build of ['chrome', 'firefox']) {
+ describe(`${build}: clock ring that empties with an auto-timeout`, () => {
+ let browser, ring, panel, css, en;
+ before(async () => {
+ browser = await chromium.launch({ headless: true });
+ ring = (await read(`src/${build}/src/ui/timeout-ring.js`)).replace(/^export /gm, '');
+ panel = await read(`src/${build}/src/ui/sidepanel.js`);
+ css = await read(`src/${build}/styles/sidepanel.css`);
+ en = (await import(`../src/${build}/src/ui/locales/en.js`)).default;
+ });
+ after(async () => { await browser?.close(); });
+
+ async function page(run) {
+ const p = await browser.newPage({ viewport: { width: 380, height: 600 } });
+ try {
+ await p.setContent('<body><div id="root"></div></body>');
+ await p.addStyleTag({ content: css });
+ await p.addScriptTag({ content: `
+ const EN = ${JSON.stringify(en)};
+ function t(key, params = {}) { return String(EN[key] || key).replace(/\\{(\\w+)\\}/g, (_, k) => params[k] ?? ''); }
+ window.submitted = [];
+ function submitClarify(card, tabId, clarifyId, answer, source) { window.submitted.push({ answer, source }); card.classList.add('clarify-answered'); }
+ ${ring}
+ ${extract(panel, 'clearClarifyCountdown')}
+ ${extract(panel, 'startClarifyCountdown')}
+ ${extract(panel, 'stopPlanReviewTimeoutRing')}
+ ${extract(panel, 'startPlanReviewTimeoutRing')}
+ Object.assign(window, { createTimeoutRing, updateTimeoutRing, startClarifyCountdown, startPlanReviewTimeoutRing, stopPlanReviewTimeoutRing });
+ ` });
+ return await run(p);
+ } finally { await p.close(); }
+ }
+
+ test('it empties clockwise as the time runs out and warns when little is left', async () => {
+ await page(async (p) => {
+ const read = (share) => p.evaluate((s) => {
+ const r = window.createTimeoutRing();
+ document.getElementById('root').appendChild(r);
+ window.updateTimeoutRing(r, s * 120_000, 120_000);
+ return {
+ offset: Number(r.querySelector('.timeout-ring-progress').getAttribute('stroke-dashoffset')),
+ circumference: Number(r.querySelector('.timeout-ring-progress').getAttribute('stroke-dasharray')),
+ hand: r.querySelector('.timeout-ring-hand').getAttribute('transform'),
+ low: r.classList.contains('timeout-ring-low'), title: r.title, text: r.textContent, hidden: r.getAttribute('aria-hidden'),
+ };
+ }, share);
+ const full = await read(1), half = await read(.5), empty = await read(0);
+ assert.equal(full.offset, 0, 'a full ring at the start');
+ assert.ok(Math.abs(half.offset - half.circumference / 2) < .01, 'half the ring is gone at half time');
+ assert.ok(Math.abs(empty.offset - empty.circumference) < .01, 'nothing is left at the end');
+ assert.equal(full.hand, 'rotate(0.0 12 12)'); assert.equal(half.hand, 'rotate(180.0 12 12)'); assert.equal(empty.hand, 'rotate(360.0 12 12)');
+ assert.equal(full.low, false); assert.equal(half.low, false); assert.equal(empty.low, true);
+ assert.equal(full.title, '2:00'); assert.equal(half.title, '1:00'); assert.equal(empty.title, '0:00');
+ assert.equal(full.text, '', 'the ring carries no text, so it needs no translation');
+ assert.equal(full.hidden, 'true');
+ });
+ });
+
+ test('the clarification card shows it in the bottom-right corner and keeps its text countdown', async () => {
+ await page(async (p) => {
+ const result = await p.evaluate(async () => {
+ const card = document.createElement('div');
+ card.className = 'clarify-card';
+ card.style.width = '320px';
+ const button = document.createElement('button');
+ button.className = 'clarify-option'; button.textContent = 'Commit it';
+ card.appendChild(button);
+ card.dataset.timeoutSec = '30';
+ document.getElementById('root').appendChild(card);
+ window.startClarifyCountdown(card, { tabId: 1, clarifyId: 'c1', deadlineTs: Date.now() + 30_000, firstOption: 'Commit it' });
+ const early = Number(card.querySelector('.timeout-ring-progress').getAttribute('stroke-dashoffset'));
+ await new Promise((r) => setTimeout(r, 1300));
+ const later = Number(card.querySelector('.timeout-ring-progress').getAttribute('stroke-dashoffset'));
+ const c = card.getBoundingClientRect(), r = card.querySelector('.timeout-ring').getBoundingClientRect();
+ return { early, later, rightGap: c.right - r.right, bottomGap: c.bottom - r.bottom, label: card.querySelector('.clarify-timeout').textContent, rings: card.querySelectorAll('.timeout-ring').length };
+ });
+ assert.equal(result.rings, 1);
+ assert.match(result.label, /^Picks β€œCommit it” in (28|29|30)s$/, 'the text countdown is unchanged');
+ assert.ok(result.later > result.early, 'the ring empties as time passes');
+ assert.ok(result.rightGap >= 0 && result.rightGap <= 16, `right edge (${result.rightGap})`);
+ assert.ok(result.bottomGap >= 0 && result.bottomGap <= 16, `bottom edge (${result.bottomGap})`);
+ });
+ });
+
+ test('a clarification card that was already running restarts from what is left, then drops the ring when answered', async () => {
+ await page(async (p) => {
+ const result = await p.evaluate(async () => {
+ const card = document.createElement('div');
+ card.className = 'clarify-card';
+ document.getElementById('root').appendChild(card);
+ // No timeoutSec (restored card): the time left when it starts is the whole period.
+ window.startClarifyCountdown(card, { tabId: 1, clarifyId: 'c2', deadlineTs: Date.now() + 20_000, firstOption: 'A' });
+ const start = Number(card.querySelector('.timeout-ring-progress').getAttribute('stroke-dashoffset'));
+ card.classList.add('clarify-answered');
+ await new Promise((r) => setTimeout(r, 400));
+ return { start, rings: card.querySelectorAll('.timeout-ring').length };
+ });
+ assert.ok(result.start < 1, 'starts (nearly) full');
+ assert.equal(result.rings, 0, 'the ring goes away with the countdown');
+ });
+ });
+
+ test('the plan review card shows it at the end of the action row until the review is settled', async () => {
+ await page(async (p) => {
+ const result = await p.evaluate(async () => {
+ const card = document.createElement('div');
+ card.className = 'plan-review-card';
+ card.style.width = '340px';
+ card.innerHTML = '<div class="plan-review-actions"><button class="plan-review-approve">Run</button><button class="plan-review-change">Edit as text</button><button class="plan-review-cancel">Cancel</button></div>';
+ card.dataset.timeoutSec = '120';
+ card.dataset.deadlineTs = String(Date.now() + 90_000);
+ document.getElementById('root').appendChild(card);
+ window.startPlanReviewTimeoutRing(card);
+ const ring = card.querySelector('.plan-review-actions .timeout-ring');
+ const first = Number(ring.querySelector('.timeout-ring-progress').getAttribute('stroke-dashoffset'));
+ const actions = card.querySelector('.plan-review-actions').getBoundingClientRect(), r = ring.getBoundingClientRect();
+ const cancel = card.querySelector('.plan-review-cancel').getBoundingClientRect();
+ // Starting again (rebind) never stacks a second ring.
+ window.startPlanReviewTimeoutRing(card);
+ const rings = card.querySelectorAll('.timeout-ring').length;
+ card.classList.add('plan-reviewed');
+ await new Promise((res) => setTimeout(res, 500));
+ return { first, rings, afterSettled: card.querySelectorAll('.timeout-ring').length, atEnd: actions.right - r.right, beyondButtons: r.left >= cancel.right - 1 };
+ });
+ // 90 s of 120 s left: a quarter of the ring is gone.
+ assert.ok(result.first > 10 && result.first < 18, `quarter emptied (${result.first})`);
+ assert.equal(result.rings, 1);
+ assert.equal(result.afterSettled, 0, 'settling the review removes the ring');
+ assert.ok(result.atEnd >= 0 && result.atEnd <= 4, 'at the end of the row');
+ assert.equal(result.beyondButtons, true, 'it does not overlap the buttons');
+ });
+ });
+
+ test('a plan whose time has already run out gets no ring; a card without a deadline gets none either', async () => {
+ await page(async (p) => {
+ const counts = await p.evaluate(() => {
+ const make = (deadline) => {
+ const card = document.createElement('div');
+ card.className = 'plan-review-card';
+ card.innerHTML = '<div class="plan-review-actions"></div>';
+ if (deadline != null) { card.dataset.timeoutSec = '120'; card.dataset.deadlineTs = String(deadline); }
+ document.getElementById('root').appendChild(card);
+ window.startPlanReviewTimeoutRing(card);
+ return card.querySelectorAll('.timeout-ring').length;
+ };
+ return [make(Date.now() - 1000), make(null)];
+ });
+ assert.deepEqual(counts, [0, 0]);
+ });
+ });
+ });
+}
+
+test('both agents tell the panel when the plan review runs out', async () => {
+ for (const build of ['chrome', 'firefox']) {
+ const agent = await read(`src/${build}/src/agent/agent.js`);
+ assert.match(agent, /onUpdate\('plan_review', \{\s*planId, plan, markdown, verboseMarkdown,\s*timeoutSec: Math\.round\(PLAN_REVIEW_TIMEOUT_MS \/ 1000\),\s*deadlineTs: Date\.now\(\) \+ PLAN_REVIEW_TIMEOUT_MS,/, build);
+ const panel = await read(`src/${build}/src/ui/sidepanel.js`);
+ assert.match(panel, /card\.dataset\.deadlineTs = String\(Math\.floor\(planDeadlineTs\)\)/, `${build}: the plan card keeps the deadline so a restored card can rebuild the ring`);
+ assert.match(panel, /function bindPlanReviewCard\(card\) \{[\s\S]*?startPlanReviewTimeoutRing\(card\);/, `${build}: binding (also after restore) starts the ring`);
+ }
+});