An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
fix(timer): count a fire that found no daemon connected as a skip, not as a run it never made
Shahriard9c32aa703aa
diff --git a/src/lib/bridge/run-port.ts b/src/lib/bridge/run-port.tsindex d220531..351a4b4 100644--- a/src/lib/bridge/run-port.ts+++ b/src/lib/bridge/run-port.ts@@ -179,8 +179,8 @@ export function serveRunPorts(): void {if (!session) return 'gone';if (session.runId || busy.has(sessionId)) return 'busy';await append(sessionId, notice('info', `Timer “${label}” fired.`));- await startTurn(session, prompt, { fastPath: false });- return 'delivered';+ const outcome = await startTurn(session, prompt, { fastPath: false });+ return outcome === 'busy' || outcome === 'offline' ? outcome : 'delivered';}),);diff --git a/src/lib/bridge/timer.test.ts b/src/lib/bridge/timer.test.tsnew file mode 100644index 0000000..2bd4974--- /dev/null+++ b/src/lib/bridge/timer.test.ts@@ -0,0 +1,57 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { fakeBrowser } from 'wxt/testing';+import { timerAlarm, type TimerState } from '@/lib/timers/events';+import { onTimerFire, serveTimers, startJobTimer, timerStatusFor, type TimerHandoff } from './timer';++const handoff = vi.fn<() => Promise<TimerHandoff>>();++async function scheduled(): Promise<string> {+ const started = await startJobTimer(+ { prompt: 'Reload the queue.', afterMs: 60_000, repeat: false, maxRuns: 1, deliver: 'agent' },+ 'session-1',+ );+ if (!started.ok) throw new Error(started.error.message);+ return (started.data as TimerState).timerId;+}++async function fire(timerId: string): Promise<void> {+ await fakeBrowser.alarms.onAlarm.trigger({ name: timerAlarm(timerId), scheduledTime: Date.now() });+}++async function status(timerId: string): Promise<TimerState> {+ const result = await timerStatusFor(timerId);+ if (!result.ok) throw new Error(result.error.message);+ return result.data as TimerState;+}++describe('a timer handing work to its conversation', () => {+ beforeEach(() => {+ fakeBrowser.reset();+ handoff.mockReset();+ serveTimers();+ onTimerFire(handoff);+ });++ it('counts a fire with no daemon connected as a skip, not a run', async () => {+ handoff.mockResolvedValue('offline');+ const timerId = await scheduled();++ await fire(timerId);++ await vi.waitFor(async () => expect((await status(timerId)).skipped).toBe(1));+ const state = await status(timerId);+ expect(state.runs).toBe(0);+ expect(state.phase).toBe('scheduled');+ expect(state.logs.at(-1)?.text).toBe('Skipped — no Browsentic daemon was connected to run it.');+ });++ it('finishes a one-shot timer once its prompt was delivered', async () => {+ handoff.mockResolvedValue('delivered');+ const timerId = await scheduled();++ await fire(timerId);++ await vi.waitFor(async () => expect((await status(timerId)).phase).toBe('finished'));+ expect((await status(timerId)).runs).toBe(1);+ });+});diff --git a/src/lib/bridge/timer.ts b/src/lib/bridge/timer.tsindex 0d5a89e..437f977 100644--- a/src/lib/bridge/timer.ts+++ b/src/lib/bridge/timer.ts@@ -37,7 +37,12 @@ interface ScheduledTimer {logs: TimerLogEntry[];}-export type TimerHandoff = 'delivered' | 'busy' | 'gone';+export type TimerHandoff = 'delivered' | 'busy' | 'offline' | 'gone';++const SKIPPED: Record<Exclude<TimerHandoff, 'delivered' | 'gone'>, string> = {+ busy: 'Skipped — the conversation was still working on the previous turn.',+ offline: 'Skipped — no Browsentic daemon was connected to run it.',+};type Deliverer = (sessionId: string, prompt: string, label: string) => Promise<TimerHandoff>;@@ -184,9 +189,9 @@ async function fireTimer(timerId: string): Promise<void> {const timer = map[timerId];if (!timer) return null;const now = Date.now();- if (outcome === 'busy') {+ if (outcome !== 'delivered') {timer.skipped += 1;- appendLog(timer, 'Skipped — the conversation was still working on the previous turn.');+ appendLog(timer, SKIPPED[outcome]);} else {timer.runs += 1;timer.lastFiredAt = now;@@ -202,7 +207,7 @@ async function fireTimer(timerId: string): Promise<void> {await finishTimer(timerId,'finished',- `Gave up after ${advanced.skipped} fires found the conversation still busy — the job takes longer than the interval it was given.`,+ `Gave up after ${advanced.skipped} fires could not run — the conversation stayed busy, or no daemon was connected.`,);return;}