Add server-only leak pass to next-bundle-optimizer (#100330)
## Summary
The bundle optimizer ranks client code by size, so it misses small
modules that shouldn't be in the browser at all: a database schema, a
token-signing helper, an agent's system prompt. This adds a
size-independent leak pass to step 4 that walks every client-reachable
module in the analyzer export and checks it against content heuristics.
Matches are reported in a separate "Possible server-only leaks" section
with route, shortest import chain, matched heuristics and compressed
bytes. They stay out of the size ranking and deltas, and the agent
leaves flagged modules and their import chains untouched in both modes,
since moving them is the owner's call and a size metric can't verify it.
The scan lives inline in SKILL.md rather than in a reference file. It
runs on every invocation, and in eval runs the agent skipped a reference
pointer in fix mode and missed a finding.
Also rewords one existing sentence in step 4's Done line.
Evals:
- `agent-059-bundle-audit-server-leaks`: audit mode. Two leaks
(prompt-like schema descriptions under `lib/server`, agent instructions
reached through a shared util) sit well below a lodash import in size.
Negative controls cover UI copy under
`description`/`instructions`/`prompt` keys, a `NEXT_PUBLIC_` read and a
`server-only` module used only by a Server Component.
- `agent-060-bundle-fix-server-leaks`: fix mode on the same app. Checks
the lodash fix still happens, the leaks are reported as unfixed, and
none of the flagged modules or their importers are edited.
## Verification
- `pnpm eval agent-059-bundle-audit-server-leaks`: `skills` passes,
`baseline` and `agents-md` fail
- `pnpm eval agent-060-bundle-fix-server-leaks`: `skills` passes,
`baseline` and `agents-md` fail (both edit the flagged modules)
- Not rerun: both evals after dropping the env-read case and the
`/pricing` route from the fixtures
<!-- NEXT_JS_LLM -->
---------
Co-authored-by:
vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Showing
This diff is collapsed.
Please
register
or
sign in
to comment