Skip to content

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.

Wire ego lite update notice to the real CLI upgrade remedy

0x09ae4d0b424a6
diff --git a/package/ego-browser/src/index.ts b/package/ego-browser/src/index.ts
index 4fe803a..2f019d6 100644
--- a/package/ego-browser/src/index.ts
+++ b/package/ego-browser/src/index.ts
@@ -14,6 +14,7 @@ import {
resetSink,
} from "./output-sink.js";
import { runMain } from "./run.js";
+import { emitUpdateNotice, type VersionSource } from "./update-notice.js";
type HelperFunction = (...args: unknown[]) => unknown;
type EgoRuntime = Record<string, unknown> & {
@@ -87,6 +88,13 @@ export function installEgoSdk(
installLifecycleFlush(process.stdout);
}
if (target.ego && typeof target.ego === "object") {
+ // Fire-and-forget: emitUpdateNotice never throws, and writing straight to stdout
+ // keeps it out of the output-sink buffer entirely, so it's unaffected by hard-stop
+ // discard and needs no beforeExit re-fire guard.
+ emitUpdateNotice(
+ target.ego as { getBrowserVersion?: VersionSource },
+ process.stdout,
+ );
target.ego.helpers = installed;
target.ego.learnings = {};
if (!(target.ego as Record<symbol, unknown>)[EGO_WRAPPED]) {
diff --git a/package/ego-browser/src/update-notice.test.mjs b/package/ego-browser/src/update-notice.test.mjs
index 3caebbe..fe975a9 100644
--- a/package/ego-browser/src/update-notice.test.mjs
+++ b/package/ego-browser/src/update-notice.test.mjs
@@ -4,6 +4,7 @@ import assert from "node:assert/strict";
import {
NOTICE_PREFIX,
composeNotice,
+ emitUpdateNotice,
noticeSuppressed,
probeBrowserVersion,
updateNoticeLine,
@@ -29,7 +30,7 @@ test("composeNotice renders an available update with prefix, versions, and hint"
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\(\)/);
+ assert.match(line, /run: ego-browser upgrade in your shell/);
assert.match(line, /re-read the ego-browser skill/);
});
@@ -149,3 +150,78 @@ test("updateNoticeLine swallows a throwing source", async () => {
};
assert.equal(await updateNoticeLine({ source, env: {} }), null);
});
+
+// emitUpdateNotice (the installEgoSdk wiring point) --------------------------
+
+function fakeStream() {
+ const chunks = [];
+ return {
+ write(chunk) {
+ chunks.push(String(chunk));
+ },
+ text() {
+ return chunks.join("");
+ },
+ };
+}
+
+// emitUpdateNotice is fire-and-forget: flush pending microtasks before asserting.
+function flushMicrotasks() {
+ return new Promise((resolve) => setImmediate(resolve));
+}
+
+test("emitUpdateNotice writes the notice line when the bridge reports an update", async () => {
+ const ego = {
+ getBrowserVersion: async () => ({
+ currentVersion: "0.4.3.0",
+ updateAvailable: true,
+ latestVersion: "0.4.4.0",
+ }),
+ };
+ const stream = fakeStream();
+ emitUpdateNotice(ego, stream, {});
+ await flushMicrotasks();
+ assert.ok(stream.text().startsWith(NOTICE_PREFIX));
+ assert.match(stream.text(), /run: ego-browser upgrade in your shell/);
+});
+
+test("emitUpdateNotice stays silent when there is no update", async () => {
+ const ego = {
+ getBrowserVersion: async () => ({
+ currentVersion: "0.4.3.0",
+ updateAvailable: false,
+ }),
+ };
+ const stream = fakeStream();
+ emitUpdateNotice(ego, stream, {});
+ await flushMicrotasks();
+ assert.equal(stream.text(), "");
+});
+
+test("emitUpdateNotice stays silent when the bridge method is missing (older build)", async () => {
+ const stream = fakeStream();
+ emitUpdateNotice({}, stream, {});
+ await flushMicrotasks();
+ assert.equal(stream.text(), "");
+});
+
+test("emitUpdateNotice stays silent when there is no ego bridge at all", async () => {
+ const stream = fakeStream();
+ emitUpdateNotice(null, stream, {});
+ await flushMicrotasks();
+ assert.equal(stream.text(), "");
+});
+
+test("emitUpdateNotice is suppressed in CI even when an update is available", async () => {
+ const ego = {
+ getBrowserVersion: async () => ({
+ currentVersion: "0.4.3.0",
+ updateAvailable: true,
+ latestVersion: "0.4.4.0",
+ }),
+ };
+ const stream = fakeStream();
+ emitUpdateNotice(ego, stream, { CI: "true" });
+ await flushMicrotasks();
+ assert.equal(stream.text(), "");
+});
diff --git a/package/ego-browser/src/update-notice.ts b/package/ego-browser/src/update-notice.ts
index 35a0246..2e6ce94 100644
--- a/package/ego-browser/src/update-notice.ts
+++ b/package/ego-browser/src/update-notice.ts
@@ -10,10 +10,12 @@
* 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 version check is `ego.getBrowserVersion()`, a real bridge method on current app
+ * builds; on older builds without it, the default source (`probeBrowserVersion`)
+ * degrades to "no update". The remedy is *not* a symmetric `ego.upgradeBrowser()`
+ * bridge call — the app exposes that half as the native CLI subcommand
+ * `ego-browser upgrade` instead, so the composed line tells the agent to run it as a
+ * shell command.
*
* The whole module is pure given an injected version source, so it is exercised
* without a real browser.
@@ -27,7 +29,7 @@ export type BrowserVersionInfo = {
mandatory?: boolean;
};
-/** The injectable seam for the (not-yet-shipped) client version query. */
+/** The injectable seam for the client version query. */
export type VersionSource = () => Promise<
BrowserVersionInfo | null | undefined
>;
@@ -68,13 +70,13 @@ export function composeNotice(
? `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(), then re-read the ego-browser skill`;
+ return `${NOTICE_PREFIX} ${target} ${urgency} (current ${info.currentVersion}) — run: ego-browser upgrade in your shell, then re-read the ego-browser skill`;
}
/**
* 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.
+ * otherwise returns null — older builds without the method simply report "no update"
+ * instead of erroring.
*/
export async function probeBrowserVersion(): Promise<BrowserVersionInfo | null> {
const ego = (globalThis as { ego?: { getBrowserVersion?: VersionSource } })
@@ -86,10 +88,8 @@ export async function probeBrowserVersion(): Promise<BrowserVersionInfo | 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.
+ * Ask the source, return the line to append, or null. Swallows every failure: an
+ * update check must never be what breaks a command.
*/
export async function updateNoticeLine(
options: { source?: VersionSource; env?: NodeJS.ProcessEnv } = {},
@@ -103,3 +103,29 @@ export async function updateNoticeLine(
return null;
}
}
+
+/** A stream that can receive the notice line. */
+export type NoticeWritable = { write(chunk: string): unknown };
+
+/**
+ * The one real emit point: given the app's injected `ego` bridge (or none, on older
+ * builds), fire the check and write the resulting line straight to `stream` if there
+ * is one. Fire-and-forget — `installEgoSdk()` calls this without awaiting it, so the
+ * check runs concurrently with the rest of the heredoc rather than delaying it.
+ *
+ * Writes directly to `stream` rather than through the output-sink buffer: an update
+ * hint is unrelated to whether the command's own business logic hard-stopped, so it
+ * must not be swallowed by (or dilute) that unrelated discard-on-hard-stop path.
+ */
+export function emitUpdateNotice(
+ ego: { getBrowserVersion?: VersionSource } | null | undefined,
+ stream: NoticeWritable,
+ env?: NodeJS.ProcessEnv,
+): void {
+ updateNoticeLine({
+ source: () => ego?.getBrowserVersion?.() ?? Promise.resolve(null),
+ env,
+ }).then((line) => {
+ if (line) stream.write(`${line}\n`);
+ });
+}