Agent Context
AGENTS.md — @inbrowser/driver
Preload budget, zero-dependency boundaries, wire validation, and verification rules for @inbrowser/driver.
Purpose
@inbrowser/driver provides fast 1-RTT semantic browser UI observation, transactional multi-step actions, silent/GPU visual capture, and structured agent tool handlers (ui_observe, ui_act, ui_capture, opt-in ui_eval) across <iframe> previews, MessagePort channels, @inbrowser/node container previews, and real Chrome DevTools Protocol tabs (puppeteer-core).
Architectural Boundaries
- Zero Core Runtime Dependencies:
@inbrowser/driverships zerodependencies. Optional ecosystem integrations (@inbrowser/node,@inbrowser/agent,@inbrowser/sandbox,puppeteer-core) live strictly in optionalpeerDependencies. - Self-Contained Preload (
<= 44 KiBminified,<= 16 KiBgzipped):src/preload/entry.tscompiles into a minified IIFE (dist/preload.iife.js) injected into guest frames. Modules undersrc/preload/**may only import sibling modules insrc/preload/or pure leaf contracts (src/types.ts,src/protocol.ts), and must capture browser intrinsics insrc/preload/intrinsics.tsbefore guest scripts run. - Browser-Safe Core & Tools:
src/index.ts,src/types.ts,src/protocol.ts,src/preload/**,src/host/**, andsrc/tools/**must never importnode:*modules orpuppeteer-core. Onlysrc/puppeteer/**may importpuppeteer-core. - Untrusted Wire Inputs: Cross-origin
MessagePortenvelopes are untrusted inputs. Validate channel namespaces, protocol versions, message kinds, and payload shapes using runtime type guards (unknown-> narrowed types). Never useany; anyasassertion other thanas constrequires an immediately preceding or same-line// Invariant:comment explaining why runtime narrowing cannot express it. - Explicit Unsupported Seams: Unimplemented capabilities throw a coded
DriverError(DRIVER_UNSUPPORTEDorDRIVER_EVAL_DISABLED) rather than returning silent fake success. - Deterministic Resource Teardown: Every pending operation requires an owner, timeout or
AbortSignalpath, anddispose()cleanup. Shut down fixture HTTP servers and Playwright resources insidetry / finallyblocks so zero ports or workers leak.
Testing & Verification
- Unit Tier (
bun run --cwd packages/driver test): Fast pure-TypeScript Vitest suites undertests/unit/**/*.unit.test.ts(protocol codecs, diffing, fingerprint matching, output formatting, compile-time ecosystem assignability). - Browser Acceptance Tier (
bun run test:e2e:driver): Real Chromium Playwright specs undertests/*.spec.tsagainst multi-origin HTTP fixtures (DRIVER_TEST_PORT, default4700) and the 3-origin@inbrowser/nodeSandboxContainerharness. Build@inbrowser/nodeand@inbrowser/driverbefore running E2E specs. Never substitute JSDOM or internal collaborator mocks for real browser behavior. - Boundary & Hygiene Gate (
bun run build:driver): Runsscripts/build.mjs(preload raw/gzip byte budgets, core/preload metafile graph checks, declaration emit withtypes: [], export target checks) followed byscripts/check-boundaries.mjs(AST import graph,any/bare-asinvariant check, hygiene rules).