Repository navigation
Commit 835c09a
authored
docs: explain the light and browser third-party bundles in AGENTS.md (#3529)
Refs #3427
Lazy loading part 11 of 11, stacked on #3526. The server still loads
`third_party/browser.js` at startup through `index.ts`, `McpContext` and
`McpResponse`, until a follow-up PR loads it on the first tool call.
## What
Documents the bundle split from this series so that new code keeps tool,
config and telemetry modules free of the browser bundle.
- **AGENTS.md, new "Third-party bundles" section under "Instructions":**
- `src/third_party/index.ts` is the light bundle loaded at startup (MCP
SDK, zod, ajv). `src/third_party/browser.ts` is the heavy bundle
(Puppeteer, `@puppeteer/browsers`, DevTools frontend) and should only
load once a tool call needs it. The wording describes the goal; it does
not claim the server already avoids loading `browser.js` at startup.
- Types from `browser.js` can be imported anywhere with `import type`.
- Tool definitions, config and telemetry modules must not import values
from `browser.js`. They get them in the handler via `await
loadBrowser()`, a dynamic `import()`, or page and context objects.
Values used when the module loads, such as in a schema, must come from
modules without browser code, like `utils/logpoint.ts` and
`formatters/constants.ts`.
- Classes checked with `instanceof` (for example `TimeoutError`) come
only from `browser.js`. Small pure modules may be re-exported from
`index.ts` by their direct file path.
- `tests/browser-imports.test.ts` lists the modules that must not reach
`browser.js`, and new tool, config and telemetry modules should be added
to it.
- **AGENTS.md pre-submit checklist ("Design"):** new item "Tool, config
and telemetry modules do not import values from
`src/third_party/browser.js`".
- **Header comments** at the top of `src/third_party/index.ts` and
`src/third_party/browser.ts` saying what belongs in each bundle.
At this commit, no module under `src/config/`, `src/telemetry/` or
`src/tools/` statically reaches `third_party/browser.js`. I checked this
by walking the imports of the built JS, so the rules match the code.
## Test plan
- `npm run format`.
- `npm run test tests/browser-imports.test.ts
tests/cli-imports.test.ts`. The code change is comments only.1 parent ebb27f9 commit 835c09a
3 files changed
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
13 | 31 | | |
14 | 32 | | |
15 | 33 | | |
| |||
91 | 109 | | |
92 | 110 | | |
93 | 111 | | |
| 112 | + | |
| 113 | + | |
94 | 114 | | |
95 | 115 | | |
96 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
0 commit comments