# AGENTS.md Instructions for coding agents that change browserclaw itself. To use browserclaw in another project, read `.claude/skills/browserclaw/SKILL.md` instead. ## Layout - `src/`: the library. `src/browser.ts` holds the public `BrowserClaw` and `CrawlPage` classes; `src/index.ts` is the package entry. - `src/actions/`: clicks, typing, navigation, waits, batch, uploads and the navigation fence. - `src/snapshot/`: aria and role snapshots, ref maps, DOM enrichment, sensitive-value redaction. - `src/agent-docs/`: the guide renderer, the `help` data generator and the doc tests' helpers. - `src/cli.ts`: the `browserclaw` bin (`npx browserclaw skill`, `npx browserclaw help`). It imports only `node:` builtins and `src/agent-docs/api-format.ts`. - `src/option-keys.ts`: the option-name registry behind `UnknownOptionError`. - `docs/agent-guide.md`: the agent usage guide, rendered into `dist/guide.md` at build. - `plugins/`, `.claude-plugin/`, `.agents/plugins/`, `.cursor-plugin/`: plugin listings. - `scripts/`: export and package checks, the skill sync and the git hook installer. ## Commands - Verify everything: `npm run format:check && npm run lint && npm run typecheck && npm run build && npm test` - One test file: `npx vitest run src/option-keys.test.ts` - Integration tests (`*.integration.test.ts`) need Chromium: `npx playwright-core install chromium`. Use a scratch `userDataDir` and a non-default `cdpPort` in anything that launches a browser. ## Conventions - ESLint (`strictTypeChecked`) and Prettier cover `src/` only. Run `npm run format:check` before pushing. - No explanatory comments; one short line only when a WHY is needed. Keep existing provenance comments (`// Adapted from …`, OpenClaw origin notes). - Never write an empty `catch`; log a warning with `console.warn('[browserclaw] …')`. - Every option of a public `CrawlPage` or `BrowserClaw` method is listed in `src/option-keys.ts`, and the method's first statement is `assertKnownOptions('', …params)`. `npm run typecheck` fails when the registry and the types disagree; `src/option-keys.test.ts` checks the call sites. - Public methods carry JSDoc: `npx browserclaw help` prints it, and every method needs a summary. ## Security invariants The SSRF navigation fence and sensitive-value redaction must not weaken. Changes to `src/security.ts`, `src/actions/navigation-fence.ts`, `src/actions/navigation.ts`, `src/snapshot/sensitive-field-values.ts`, `src/snapshot/aria-snapshot.ts` or `src/snapshot/native-capture.ts` need tests that show the fence and the redaction still hold. ## OpenClaw sync The code originates in OpenClaw's browser tool. Mirrored low-level functions (`*ViaPlaywright`, `executeSingleAction`, `batchViaPlaywright`) keep parity with OpenClaw and do not validate options. Maintainers track intentional divergences outside the repo. When a sync adds an option key, add it to `src/option-keys.ts`. ## Agent docs pipeline - Edit `docs/agent-guide.md` for the guide and `.claude/skills/browserclaw/SKILL.md` for the short entry skill, then run `npm run sync:agent-skills`. It copies the entry skill to `.agents/skills/browserclaw/SKILL.md` and `plugins/browserclaw/skills/browserclaw/SKILL.md` and writes the package version into the plugin and marketplace manifests. `npm version` runs it through the `version` script. - Never edit the generated copies. `src/agent-docs.test.ts` fails on drift, on an entry skill over 3,500 characters, on a guide over 18,000 characters, on a code block that does not type-check, and on a method name that does not exist. - The entry skill's to-do example and refs rule must stay identical to the guide's first example and Key rule 2. ## Releases Version bumps and npm publishing are done by the maintainer. Do not change the `package.json` version.