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
Keep the plan-review deadline for recovered cards and drain the ring with the hand
Claudeab0a451c3ffc
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 814c9375b..c543b5e5a 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -7855,6 +7855,8 @@ export class Agent extends LoopDetector {plan: entry?.plan || null,markdown: entry?.markdown || '',verboseMarkdown: entry?.verboseMarkdown || '',+ // A reopened panel needs the deadline to draw the countdown ring.+ ...(entry?.timeoutSec > 0 && entry?.deadlineTs > 0 ? { timeoutSec: entry.timeoutSec, deadlineTs: entry.deadlineTs } : {}),};}return state;@@ -22122,8 +22124,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst PLAN_REVIEW_TIMEOUT_MS = 2 * 60 * 1000;const tabPending = this._pendingPlans.get(tabId) || new Map();this._pendingPlans.set(tabId, tabPending);+ const deadlineTs = Date.now() + PLAN_REVIEW_TIMEOUT_MS;+ const timeoutSec = Math.round(PLAN_REVIEW_TIMEOUT_MS / 1000);const responsePromise = new Promise((resolve) => {- tabPending.set(planId, { resolve, ts: Date.now(), plan, markdown, verboseMarkdown });+ tabPending.set(planId, { resolve, ts: Date.now(), plan, markdown, verboseMarkdown, timeoutSec, deadlineTs });});let timeoutId = null;const timeoutPromise = new Promise((resolve) => {@@ -22137,8 +22141,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 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,+ timeoutSec,+ deadlineTs,});} catch {}}diff --git a/src/chrome/src/ui/timeout-ring.js b/src/chrome/src/ui/timeout-ring.jsindex f9a5034fd..3117099c3 100644--- a/src/chrome/src/ui/timeout-ring.js+++ b/src/chrome/src/ui/timeout-ring.js@@ -48,7 +48,7 @@ export function updateTimeoutRing(ring, remainingMs, totalMs) {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 (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/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 0d31ed493..72f67f4c7 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -7396,6 +7396,8 @@ export class Agent extends LoopDetector {plan: entry?.plan || null,markdown: entry?.markdown || '',verboseMarkdown: entry?.verboseMarkdown || '',+ // A reopened panel needs the deadline to draw the countdown ring.+ ...(entry?.timeoutSec > 0 && entry?.deadlineTs > 0 ? { timeoutSec: entry.timeoutSec, deadlineTs: entry.deadlineTs } : {}),};}return state;@@ -19188,8 +19190,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst PLAN_REVIEW_TIMEOUT_MS = 2 * 60 * 1000;const tabPending = this._pendingPlans.get(tabId) || new Map();this._pendingPlans.set(tabId, tabPending);+ const deadlineTs = Date.now() + PLAN_REVIEW_TIMEOUT_MS;+ const timeoutSec = Math.round(PLAN_REVIEW_TIMEOUT_MS / 1000);const responsePromise = new Promise((resolve) => {- tabPending.set(planId, { resolve, ts: Date.now(), plan, markdown, verboseMarkdown });+ tabPending.set(planId, { resolve, ts: Date.now(), plan, markdown, verboseMarkdown, timeoutSec, deadlineTs });});let timeoutId = null;const timeoutPromise = new Promise((resolve) => {@@ -19203,8 +19207,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 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,+ timeoutSec,+ deadlineTs,});} catch {}}diff --git a/src/firefox/src/ui/timeout-ring.js b/src/firefox/src/ui/timeout-ring.jsindex f9a5034fd..3117099c3 100644--- a/src/firefox/src/ui/timeout-ring.js+++ b/src/firefox/src/ui/timeout-ring.js@@ -48,7 +48,7 @@ export function updateTimeoutRing(ring, remainingMs, totalMs) {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 (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/test/plan-review-notifications.mjs b/test/plan-review-notifications.mjsindex 587186dc5..6fd258844 100644--- a/test/plan-review-notifications.mjs+++ b/test/plan-review-notifications.mjs@@ -312,6 +312,25 @@ for (const item of builds) {assert.equal(h.audio.length, 1, 'Resolving the plan must not replay its alert');});+ test(`${item.build}: a plan review recovered after the panel reopens keeps its deadline for the countdown ring`, async t => {+ const agent = new item.Agent({ getActive: () => ({}) });+ t.mock.timers.enable({ apis: ['setTimeout', 'Date'] });+ const updates = [];+ // The side panel is closed: the live update has no receiver.+ const waiting = agent._waitForPlanReview(77, 'plan-1', { steps: [] }, 'Plan', (type, data) => updates.push({ type, data }));+ await flush();+ const live = updates.find(update => update.type === 'plan_review').data;+ assert.equal(live.timeoutSec, 120);+ t.mock.timers.tick(30_000);+ const recovered = agent.activeRunState(77).pendingPlan;+ assert.equal(recovered.planId, 'plan-1');+ assert.equal(recovered.timeoutSec, 120, 'the recovered plan carries the period');+ assert.equal(recovered.deadlineTs, live.deadlineTs, 'and the same deadline as the live update, not a fresh one');+ assert.equal(recovered.deadlineTs - Date.now(), 90_000, 'with 30 s already used');+ agent.submitPlanResponse(77, 'plan-1', 'reject');+ await waiting;+ });+test(`${item.build}: scheduled runs use the same plan alert owner`, async () => {const h = deliveryHarness(item, { begin: false });const owner = { jobId: 'job-1', executionId: 'execution-1', mode: 'act', kind: 'resume' };diff --git a/test/run.js b/test/run.jsindex 4478eb193..48daf69dd 100644--- a/test/run.js+++ b/test/run.js@@ -120099,7 +120099,7 @@ test('planner gate: background exposes pending plan state for restored sidepanelconst bgSource = fs.readFileSync(path.join(ROOT, bgRel), 'utf8');assert.match(agentSource, /activeRunState\(tabId\)/, `${label}: agent should expose active run state`);assert.match(agentSource, /pendingPlan:[\s\S]*?null/, `${label}: active run state should include pendingPlan`);- assert.match(agentSource, /tabPending\.set\(planId, \{ resolve, ts: Date\.now\(\), plan, markdown, verboseMarkdown \}\)/, `${label}: pending plans should keep renderable metadata`);+ assert.match(agentSource, /tabPending\.set\(planId, \{ resolve, ts: Date\.now\(\), plan, markdown, verboseMarkdown, timeoutSec, deadlineTs \}\)/, `${label}: pending plans should keep renderable metadata and the review deadline`);assert.match(bgSource, /case 'agent_run_state':[\s\S]*?agent\.activeRunState\(tabId\)/, `${label}: background should expose active run state to the sidepanel`);}});diff --git a/test/timeout-ring.mjs b/test/timeout-ring.mjsindex b31504153..228de3b59 100644--- a/test/timeout-ring.mjs+++ b/test/timeout-ring.mjs@@ -62,8 +62,9 @@ for (const build of ['chrome', 'firefox']) {}, 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.ok(Math.abs(half.offset + half.circumference / 2) < .01, 'half the ring is gone at half time, removed from 12 o\'clock clockwise like the hand');+ assert.ok(Math.abs(empty.offset + empty.circumference) < .01, 'nothing is left at the end');+ assert.ok(half.offset < 0, 'a negative offset removes the start of the arc (where the hand has swept), not its trailing 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');@@ -92,7 +93,7 @@ for (const build of ['chrome', 'firefox']) {});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.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})`);});@@ -111,7 +112,7 @@ for (const build of ['chrome', 'firefox']) {await new Promise((r) => setTimeout(r, 400));return { start, rings: card.querySelectorAll('.timeout-ring').length };});- assert.ok(result.start < 1, 'starts (nearly) full');+ assert.ok(result.start > -1, 'starts (nearly) full');assert.equal(result.rings, 0, 'the ring goes away with the countdown');});});@@ -139,7 +140,7 @@ for (const build of ['chrome', 'firefox']) {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.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');@@ -170,7 +171,9 @@ for (const build of ['chrome', 'firefox']) {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);+ assert.match(agent, /onUpdate\('plan_review', \{\s*planId, plan, markdown, verboseMarkdown,\s*timeoutSec,\s*deadlineTs,\s*\}\)/, `${build}: the live plan_review update carries the period and the deadline`);+ assert.match(agent, /tabPending\.set\(planId, \{[^}]*timeoutSec, deadlineTs \}\)/, `${build}: the pending entry keeps them for a reopened panel`);+ assert.match(agent, /\.\.\.\(entry\?\.timeoutSec > 0 && entry\?\.deadlineTs > 0 \? \{ timeoutSec: entry\.timeoutSec, deadlineTs: entry\.deadlineTs \} : \{\}\)/, `${build}: the recovered pending plan carries them too`);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`);