The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
Add cache-free update-notice module for ego lite upgrade hints
0x0c9f861ee29de
diff --git a/package/ego-browser/src/update-notice.test.mjs b/package/ego-browser/src/update-notice.test.mjsnew file mode 100644index 0000000..252c5a8--- /dev/null+++ b/package/ego-browser/src/update-notice.test.mjs@@ -0,0 +1,150 @@+import test from "node:test";+import assert from "node:assert/strict";++import {+ NOTICE_PREFIX,+ composeNotice,+ noticeSuppressed,+ probeBrowserVersion,+ updateNoticeLine,+} from "../dist/src/update-notice.js";++// composeNotice -------------------------------------------------------------++test("composeNotice returns null when there is nothing to report", () => {+ assert.equal(composeNotice(null), null);+ assert.equal(composeNotice(undefined), null);+ assert.equal(+ composeNotice({ currentVersion: "0.4.3.0", updateAvailable: false }),+ null,+ );+});++test("composeNotice renders an available update with prefix, versions, and hint", () => {+ const line = composeNotice({+ currentVersion: "0.4.3.0",+ updateAvailable: true,+ latestVersion: "0.4.4.0",+ });+ assert.ok(line.startsWith(NOTICE_PREFIX));+ assert.match(line, /ego lite 0\.4\.4\.0 is available/);+ assert.match(line, /current 0\.4\.3\.0/);+ assert.match(line, /await upgradeBrowser\(\)/);+});++test("composeNotice marks a mandatory update as required", () => {+ const line = composeNotice({+ currentVersion: "0.4.3.0",+ updateAvailable: true,+ latestVersion: "0.4.4.0",+ mandatory: true,+ });+ assert.match(line, /is required/);+});++test("composeNotice falls back to a generic phrase without a usable latest version", () => {+ assert.match(+ composeNotice({ currentVersion: "0.4.3.0", updateAvailable: true }),+ /an ego lite update is available/,+ );+ // A non-string latestVersion is untrusted bridge input; treat it as absent.+ assert.match(+ composeNotice({+ currentVersion: "0.4.3.0",+ updateAvailable: true,+ latestVersion: 42,+ }),+ /an ego lite update is available/,+ );+});++test("composeNotice rejects input without a usable current version", () => {+ assert.equal(composeNotice({ updateAvailable: true }), null);+});++// noticeSuppressed ----------------------------------------------------------++test("noticeSuppressed is false with a clean env", () => {+ assert.equal(noticeSuppressed({}), false);+});++test("noticeSuppressed honors the opt-out var and CI", () => {+ assert.equal(noticeSuppressed({ EGO_BROWSER_NO_UPDATE_NOTIFIER: "1" }), true);+ assert.equal(noticeSuppressed({ CI: "true" }), true);+});++// probeBrowserVersion (the mock seam) ---------------------------------------++test("probeBrowserVersion returns null until the client injects the method", async () => {+ const had = Object.prototype.hasOwnProperty.call(globalThis, "ego");+ const prev = globalThis.ego;+ try {+ delete globalThis.ego;+ assert.equal(await probeBrowserVersion(), null);+ globalThis.ego = {}; // present but without getBrowserVersion (old build)+ assert.equal(await probeBrowserVersion(), null);+ globalThis.ego = {+ getBrowserVersion: async () => ({+ currentVersion: "0.4.3.0",+ updateAvailable: false,+ }),+ };+ assert.deepEqual(await probeBrowserVersion(), {+ currentVersion: "0.4.3.0",+ updateAvailable: false,+ });+ } finally {+ if (had) globalThis.ego = prev;+ else delete globalThis.ego;+ }+});++// updateNoticeLine (the composed entry the emit points call) ----------------++test("updateNoticeLine surfaces a line when the source reports an update", async () => {+ const source = async () => ({+ currentVersion: "0.4.3.0",+ updateAvailable: true,+ latestVersion: "0.4.4.0",+ });+ const line = await updateNoticeLine({ source, env: {} });+ assert.ok(line.startsWith(NOTICE_PREFIX));+});++test("updateNoticeLine is null when the source reports no update", async () => {+ assert.equal(+ await updateNoticeLine({ source: async () => null, env: {} }),+ null,+ );+ assert.equal(+ await updateNoticeLine({+ source: async () => ({+ currentVersion: "0.4.3.0",+ updateAvailable: false,+ }),+ env: {},+ }),+ null,+ );+});++test("updateNoticeLine is null and skips the source when suppressed", async () => {+ let called = false;+ const source = async () => {+ called = true;+ return {+ currentVersion: "0.4.3.0",+ updateAvailable: true,+ latestVersion: "0.4.4.0",+ };+ };+ assert.equal(await updateNoticeLine({ source, env: { CI: "true" } }), null);+ assert.equal(called, false);+});++test("updateNoticeLine swallows a throwing source", async () => {+ const source = async () => {+ throw new Error("bridge unavailable");+ };+ assert.equal(await updateNoticeLine({ source, env: {} }), null);+});diff --git a/package/ego-browser/src/update-notice.ts b/package/ego-browser/src/update-notice.tsnew file mode 100644index 0000000..d903a8a--- /dev/null+++ b/package/ego-browser/src/update-notice.ts@@ -0,0 +1,105 @@+/**+ * "ego lite has an update" hint for the agent-facing runtime.+ *+ * Loosely modeled on lark cli's `_notice` — append one tagged line telling the+ * agent a newer ego lite exists — but deliberately WITHOUT lark's cache. lark+ * persists a throttled state file because every check is an HTTP round-trip to+ * npm, an expensive cost worth amortizing. Our source is `ego.getBrowserVersion()`:+ * a cheap local bridge call into the app, whose updater already knows+ * `updateAvailable`. There is no cost to amortize and nothing to persist, so every+ * command just asks directly and the answer is always current. (Don't re-add a+ * cache; it would only reintroduce staleness this version exists to avoid.)+ *+ * The version source is the one piece the client app still owes us:+ * `ego.getBrowserVersion()` (CITRO-2227) is not injected on any app build yet, so+ * the default source (`probeBrowserVersion`) degrades to "no update". When the real+ * method lands, nothing else here changes.+ *+ * The whole module is pure given an injected version source, so it is exercised+ * without a real browser.+ */++/** Raw shape the client `ego.getBrowserVersion()` is expected to return. */+export type BrowserVersionInfo = {+ currentVersion: string;+ updateAvailable: boolean;+ latestVersion?: string;+ mandatory?: boolean;+};++/** The injectable seam for the (not-yet-shipped) client version query. */+export type VersionSource = () => Promise<+ BrowserVersionInfo | null | undefined+>;++/** Prefix that marks the appended line as out-of-band, not real command output. */+export const NOTICE_PREFIX = "[ego-browser:notice]";++/**+ * Suppress the hint entirely. Mirrors lark's opt-out (`*_NO_UPDATE_NOTIFIER`) and+ * stays quiet in CI, where a nag line is noise no one acts on.+ */+export function noticeSuppressed(+ env: NodeJS.ProcessEnv = process.env,+): boolean {+ return Boolean(env.EGO_BROWSER_NO_UPDATE_NOTIFIER || env.CI);+}++/**+ * Format the version info into one line, or null when there is nothing to say.+ *+ * This is also the single boundary check on the bridge's return: the source crosses+ * a runtime seam (an injected app method), so untrusted fields are pinned down here+ * — a missing/non-string `currentVersion` yields null, a non-string `latestVersion`+ * degrades to the generic phrase.+ */+export function composeNotice(+ info: BrowserVersionInfo | null | undefined,+): string | null {+ if (+ !info ||+ !info.updateAvailable ||+ typeof info.currentVersion !== "string"+ ) {+ return null;+ }+ const target =+ typeof info.latestVersion === "string"+ ? `ego lite ${info.latestVersion}`+ : "an ego lite update";+ const urgency = info.mandatory ? "is required" : "is available";+ return `${NOTICE_PREFIX} ${target} ${urgency} (current ${info.currentVersion}) — run: await upgradeBrowser()`;+}++/**+ * Default version source. Calls the client method if this app build injected it,+ * otherwise returns null — old builds (and every build until CITRO-2227 ships) simply+ * report "no update" instead of erroring.+ */+export async function probeBrowserVersion(): Promise<BrowserVersionInfo | null> {+ const ego = (globalThis as { ego?: { getBrowserVersion?: VersionSource } })+ .ego;+ if (!ego || typeof ego.getBrowserVersion !== "function") {+ return null;+ }+ return (await ego.getBrowserVersion()) ?? null;+}++/**+ * The one call the emit points make: ask the source, return the line to append, or+ * null. Awaits the source directly — both emit seams (the CLI `execute()` and the+ * SDK `beforeExit` hook) can await, so no cache is needed to bridge to a sync read.+ * Swallows every failure: an update check must never be what breaks a command.+ */+export async function updateNoticeLine(+ options: { source?: VersionSource; env?: NodeJS.ProcessEnv } = {},+): Promise<string | null> {+ const env = options.env || process.env;+ if (noticeSuppressed(env)) return null;+ const source = options.source || probeBrowserVersion;+ try {+ return composeNotice((await source()) ?? null);+ } catch {+ return null;+ }+}