Skip to content

feat(cli): enforce sandboxed plugin bundle size caps - #978

Merged
ascorbic merged 2 commits into
mainfrom
feat/cli-bundle-size-caps
May 11, 2026
Merged

ascorbic merged 2 commits into
mainfrom
feat/cli-bundle-size-caps

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

Implements the bundle size caps from RFC 0001 §"Bundle size limits" in the registry CLI. Replaces the existing single 5 MB total cap with three layered caps applied uniformly in both the bundle and publish flows:

  • Total decompressed ≤ 256 KB
  • Per-file decompressed ≤ 128 KB
  • File count ≤ 20

Sized against observed first-party sandboxed plugins (largest is atproto at ~37 KB built; most are under 20 KB) — roughly 7× headroom over real-world usage. The publish-side fetch buffer drops from 5 MB to 384 KB to fit the decompressed cap plus tar headers and worst-case gzip overhead.

The publish CLI now re-validates decompressed entries against the same caps after fetching and unpacking the tarball, so a publisher hits the cap locally before the aggregator rejects the release at ingest. The fetch error tells the user both the gzipped fetch cap and the decompressed cap they actually need to satisfy, so retries aim at the right number. Tar entry filtering uses header.type === "file" rather than a trailing-slash heuristic so symlinks/hardlinks/devices/FIFOs aren't counted toward the file cap, matching what the staging-dir walk does.

Mirrored into the legacy core CLI copy (packages/core/src/cli/commands/bundle-utils.ts + bundle.ts) until phase 1 cutover, per the in-file sync comment.

Type of change

This implements the published wip/plugin-rfc branch's RFC 0001 §"Bundle size limits" subsection. The Discussion gate is the RFC itself.

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7

Test output

registry-cli: 7 files, 104 tests passing (13 new unit cases for validateBundleSize / collectBundleEntries / formatBytes / totalBundleBytes; 5 integration cases that round-trip real gzipped tarballs through the publish CLI's extractor, including a regression case for the non-file filter)
core: 204 files, 3214 tests passing

Notes for reviewers

The breaking-behavior side: any existing plugin between 256 KB and 5 MB that previously bundled fine will now be rejected by bundle and publish. The changeset calls this out. This is a deliberate cap tightening that's also the protocol contract — anything in that range would have been rejected by the aggregator at ingest anyway, so the CLI is just bringing the local-validation point in line with the published spec.

Adversarial review pass run before opening; the two HIGH/MEDIUM findings (misleading fetch error, non-file filter counting symlinks) are fixed in this PR. Remaining LOW findings (empty bundle, dotfiles, fix-guidance message text) are noted but intentionally deferred — they're not regressions and not blockers per the project's review-codes-out-of-tests rule.

Replaces the 5MB single-cap check with the three-cap enforcement from
RFC 0001 §"Bundle size limits": total decompressed ≤ 256 KB, per-file
decompressed ≤ 128 KB, and at most 20 files. Both the `bundle` command
and the `publish` command now run the same validator, so a publisher
hits the cap locally before the aggregator rejects the release at
ingest. The publish-side fetch buffer drops from 5 MB to 384 KB
(decompressed cap + tar headers + worst-case gzip overhead).

The fetch error tells the user the gzipped fetch cap *and* the
decompressed cap they actually need to satisfy, so retries aim at the
right number. The tar entry filter uses `header.type === "file"`
rather than a trailing-slash heuristic, matching what the staging-dir
walk does (`item.isFile()`) and excluding symlinks/hardlinks/devices/
fifos from the file count.

Mirrored into the legacy core CLI copy until phase 1 cutover.
Copilot AI review requested due to automatic review settings May 10, 2026 16:12
@changeset-bot

changeset-bot Bot commented May 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f4f27f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@emdash-cms/registry-cli Minor
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator f4f27f6 May 10 2026, 04:22 PM

@github-actions

Copy link
Copy Markdown
Contributor

PR template validation failed

Please fix the following issues by editing your PR description:

See CONTRIBUTING.md for the full contribution policy.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n f4f27f6 May 10 2026, 04:22 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 607 lines across 8 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs f4f27f6 May 10 2026, 04:23 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache f4f27f6 May 10 2026, 04:23 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 10, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground f4f27f6 May 10 2026, 04:24 PM

@pkg-pr-new

pkg-pr-new Bot commented May 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@978

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@978

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@978

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@978

emdash

npm i https://pkg.pr.new/emdash@978

create-emdash

npm i https://pkg.pr.new/create-emdash@978

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@978

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@978

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@978

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@978

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@978

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@978

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@978

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@978

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@978

commit: f4f27f6

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the registry CLI (and the mirrored legacy core CLI implementation) to enforce RFC 0001 sandboxed plugin bundle size limits consistently across both bundle and publish, replacing the previous single 5 MB total cap.

Changes:

  • Introduces layered bundle caps (total decompressed, per-file decompressed, and file count) and a shared validation helper (validateBundleSize) used by both bundle and publish.
  • Tightens the publish fetch buffering cap and re-validates decompressed tar entries after unpacking, with improved user-facing error messaging.
  • Adds unit + integration tests (including real gzipped-tar round trips) plus a changeset documenting the breaking behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/registry-cli/tests/publish-tarball.test.ts New integration tests that round-trip gzipped tarballs through the publish extractor and assert cap enforcement.
packages/registry-cli/tests/bundle-utils.test.ts Expanded unit coverage for bundle entry collection, byte formatting, total size calculation, and cap validation behavior.
packages/registry-cli/src/commands/publish.ts Enforces gzipped fetch cap, re-checks decompressed entries against RFC caps, and improves oversize error messaging.
packages/registry-cli/src/bundle/utils.ts Replaces single total cap with RFC caps; adds entry collection + deterministic validation helpers and shared formatBytes.
packages/registry-cli/src/bundle/api.ts Switches bundle flow from directory-total sizing to RFC cap validation over collected file entries.
packages/core/src/cli/commands/bundle.ts Mirrors updated cap validation and improved bundle size logging in the legacy core CLI bundle command.
packages/core/src/cli/commands/bundle-utils.ts Mirrors registry-cli bundle utils changes (RFC caps, entry collection, validation, formatting).
.changeset/cli-bundle-size-caps.md Documents new caps and the intentional breaking behavior for consumers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +31 to +36
async function buildTarball(files: Record<string, string | Uint8Array>): Promise<Uint8Array> {
for (const [name, body] of Object.entries(files)) {
const fullPath = join(stagingDir, name);
const dir = fullPath.slice(0, fullPath.lastIndexOf("/"));
if (dir !== stagingDir) await mkdir(dir, { recursive: true });
await writeFile(fullPath, body);
`fullPath.lastIndexOf("/")` breaks on Windows separators and returns -1
for files at the staging-dir root, in which case `slice(0, -1)` would
chop the last character off the path. `dirname()` handles both, and
`mkdir({recursive:true})` is a no-op when the directory exists, so the
extra existence check is unnecessary.

Caught by Copilot review on #978.
@ascorbic
ascorbic merged commit 27e6d58 into main May 11, 2026
35 of 36 checks passed
@ascorbic
ascorbic deleted the feat/cli-bundle-size-caps branch May 11, 2026 06:02
@emdashbot emdashbot Bot mentioned this pull request May 11, 2026
ski added a commit to ski/emdash that referenced this pull request May 20, 2026
Catches deployment/suhail-ski up with emdash-cms/emdash main. Conflict in
pnpm-lock.yaml resolved by taking upstream's lock and re-running
pnpm install to pick up the @suhailski/57th-parallel template deps.

Notable upstream changes folded in:
  - Plugin authoring CLI + manifest format (emdash-cms#1057, emdash-cms#1059)
  - Registry packages — lexicons, client, CLI (emdash-cms#923)
  - Migration 036 taxonomy preservation (emdash-cms#1086)
  - WXR import w/ WPML/Polylang translations (emdash-cms#1087)
  - TypeScript 6 upgrade, tsgo beta (emdash-cms#1074)
  - FTS5 corruption fix on publish (emdash-cms#768)
  - Plugin bundle size caps (emdash-cms#978)
  - And ~280 smaller fixes / chores

CLI rebuilt against the new core. Verified by listing posts on
suhail.ski — both tutorial posts come back as expected.

57th-parallel template untouched by upstream. Our 5 local commits
preserved across the merge.

Used --config.manage-package-manager-versions=false to bypass pnpm's
self-switch to 11.1.3, which packages weirdly on Windows. The current
shell's pnpm 10.12.4 worked fine against the merged manifests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants