Repository navigation
Minify plugin app bundles, optimize their CSS, drop provider plugin app bundles (A4, H7) - #1895
Merged
SawyerHood merged 3 commits intoAug 19, 2026
Conversation
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-build-minify
branch
from
August 19, 2026 07:42
df3a6bb to
23ea81f
Compare
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-build-minify
branch
from
August 19, 2026 07:50
23ea81f to
4e20c27
Compare
SawyerHood
marked this pull request as ready for review
August 19, 2026 08:04
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-build-minify
branch
from
August 19, 2026 15:59
4e20c27 to
fc16c75
Compare
Plugin frontend bundles shipped unminified, and every plugin's app.css
carried the utilities of all of @bb/shared-ui: `bb.pluginTailwindContent`
("src/**/*") fed the whole package glob to the Tailwind scanner whether
or not the plugin imported those components (~110 KB / ~1200 rules per
sheet, plus a `:root` block that re-declared the host's semantic token
bridge). On phones the raw bytes drive parse time, each stylesheet
insertion is a document-wide restyle, and ~17k scoped rules stay
resident.
- esbuild builds app.js with `minify: true` and `legalComments: "none"`.
`buildPluginApp` takes `{ minify }`; `bb plugin dev` passes false so
stack traces and CSS stay readable while iterating. Server installs
and `bb plugin build` minify.
- The Tailwind output plus the plugin's authored CSS run through
Tailwind's own optimizer (`optimize` from @tailwindcss/node, i.e. the
lightningcss pass the host's Vite build uses), minified in production
and pretty in dev so both modes get the same lowering.
- Dependency `bb.pluginTailwindContent` globs now only select which
files may be scanned; the scan reads the intersection with esbuild's
metafile inputs, so a plugin pays only for the shared components it
bundles. Scan bases are realpath'd because esbuild reports real paths
for workspace links.
- The generated plugin theme marks the host's `@theme inline` bridge as
`inline reference`: inline tokens are substituted into utilities at
compile time, so the `:root { --color-*: var(--*) }` block Tailwind
emitted for them was never read by plugin rules. Non-inline tokens
(Tailwind defaults, the typography scale) still emit, because the host
only defines the ones it uses itself.
Built-in bundle bytes (raw / gzip), before -> after:
tasks app.js 2,383,490 / 503,399 -> 1,257,491 / 360,279
app.css 127,234 / 15,866 -> 51,898 / 8,763
docs app.js 1,641,918 / 374,940 -> 839,167 / 262,909
app.css 112,434 / 14,127 -> 30,250 / 5,502
automations app.js 1,064,406 / 185,248 -> 587,528 / 141,850
app.css 112,712 / 14,112 -> 51,952 / 8,449
secrets app.js 644,324 / 100,199 -> 352,915 / 76,467
app.css 110,067 / 13,891 -> 17,288 / 3,321
Tests: build-output assertions for minified vs readable artifacts and
for bundled-only dependency scanning (symlinked package, negated
pattern, `:root` contents); dependent CSS assertions in the CLI, server
and plugin-registry suites updated for minified output.
Co-Authored-By: Claude <[email protected]>
provider-claude-code, provider-codex, provider-pi and provider-acp each shipped a `bb.app` entry whose only job was to register, through `app.slots.experimental_providerIcon`, an SVG byte-identical to the one the host already vendors in `BUILT_IN_BRAND_ICONS`. That cost every page load four JS fetches, four CSS fetches, four stylesheet inserts and four icon remounts for no visible change. Remove the four app.tsx files, their `bb.app` manifest entries, the `react`/`@types/react` devDependencies and `jsx` tsconfig settings that existed only for them. The host map is now the sole source of these marks; a plugin registration for one of these provider ids still wins. Update the provider-icon comment, the audit note for `experimental_providerIcon`, and the plugin-authoring skill's example, which pointed at the deleted file. Co-Authored-By: Claude <[email protected]>
The `bb plugin dev` command description now says its frontend rebuilds are unminified; docs/cli-guide-and-skill.md asks that the in-CLI guide template carry the same change. Regenerated templates.generated.ts. Co-Authored-By: Claude <[email protected]>
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-build-minify
branch
from
August 19, 2026 16:13
fc16c75 to
e3de3a9
Compare
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…closure (A2, A1) (#1894) ## What was wrong Every routed pane sits under `ThreadDetailWorkerPoolProvider`. `@pierre/diffs` constructs its `WorkerPoolManager` when the provider mounts, and the constructor spawns every worker (each ~830 KB of JavaScript plus a Shiki heap). So the root compose page and threads with no diff spawned `min(8, cores - 1)` workers on first thread paint. `PluginPanelView` mounted a second provider on top, and the theme sync called `pool.setRenderOptions` with the constructor theme on mount. `SplitWorkspaceRoute` (every thread, compose and plugin-panel page) had a static-import closure of 33 chunks, 3.45 MB raw / 893 KB brotli. It reached `@pierre/diffs` + Shiki, KaTeX, xterm and the whole secondary panel, browser deck and new-tab page before any user action. Only the boot payload was measured, so nothing stopped the closure from growing. ## What changed - The workspace provider publishes the pool through an app-owned gate context and builds it only after the first diff consumer calls `useRequirePierreWorkerPool()`. The pool manager, workers and theme sync live in a lazily loaded chunk. The provider imports nothing from `@pierre/diffs` at runtime: importing even pierre's `WorkerPoolContext` object statically drags the pool manager and Shiki into the route, because that module also defines pierre's provider. Consumers hand the pool to pierre through `PierreWorkerPoolBoundary` and render pierre only once the gate is ready (pierre captures the pool when it creates a diff instance). The plugin runtime hands plugins gated pierre components; `WorkerPoolContextProvider` and `useWorkerPool` resolve to the host pool. - `getDiffWorkerPoolSize` caps at 2 on `(pointer: coarse)` or `navigator.deviceMemory <= 4`, and at 4 elsewhere (was 8). The theme sync tracks the applied pair per pool and skips redundant `setRenderOptions`. The duplicate provider in `PluginPanelView` is gone. - `lazySecondaryPanelComponents.tsx` wraps ThreadSecondaryPanel, ThreadTerminalPanel, BrowserTabDeck, NewTabPage, FilePreview and the file-preview tab contents in `React.lazy` with local Suspense boundaries. Compact drawers realize them on first open. Inline hosts show a placeholder `Panel` with the real panel's id, order, size and bounds so the layout does not shift when the chunk lands. `TimelineFileDiffBlock` and `rehype-katex` (with its CSS) load on demand. - `vite-bundle-stats` records each measured lazy route's static closure minus the boot chunks. `check-bundle-budget.mjs` ratchets it with its own forbidden list (`routeClosures` in `bundle-budget.json`). `why-eager.mjs --from=<module>` explains a route closure. Route closure before: 3,451,217 B raw / 893,719 B brotli, 33 chunks. After: 2,377,618 B raw / 640,813 B brotli, 35 chunks (-31% raw, -28% brotli). No `@pierre/diffs`, Shiki, KaTeX or xterm remain. Budget set 3% above: 2,449,000 / 660,100. ## How you verified - New tests: `diff-worker-pool.test.ts` (pool size caps), `pierre-worker-pool-theme.test.tsx` (no `setRenderOptions` when unchanged, once per change, catch-up for a stale pool), `ThreadDetailWorkerPoolProvider.test.tsx` (no pool until a consumer asks; consumer waits then sees the pool; siblings do not remount; no-Worker path; release on unmount), `plugin-frontend.test.ts` (slot export parity with `@pierre/diffs/react`, gated components), `bundle-budget.test.ts` (route closure excludes boot and dynamic-only chunks; the check script passes, fails on a forbidden route package, fails on route bytes over budget). `markdown-preview.test.tsx` KaTeX cases now await the lazy chunk. - `pnpm exec turbo run typecheck --filter=@bb/app`, `pnpm exec turbo run lint --filter=@bb/app` (0 errors), `pnpm exec turbo run build --filter=@bb/app` then `node apps/app/scripts/check-bundle-budget.mjs` (Bundle budget OK), targeted vitest runs (114 files / 929 tests over secondary-panel, views, timeline, plugin, git-diff, markdown-preview and the new tests) all pass. Commit 1 was also typechecked and tested in isolation. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 15 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/sidebar-defer-realize` (#1893). - Next layer: `bb/mobile-perf/plugin-build-minify` (#1895). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Deliberately not done here: A1 step (d) tiptap first-focus deferral: out of scope per assignment (composer visible; tiptap allowed in the route forbidden list) - Reviewer notes / follow-ups: Follow-up (not a defect): on phones the ThreadSecondaryPanel chunk is now fetched on the first drawer open (inside the persistent drawer, after realization), so a cold-cache first | Follow-up (by design of A2): the first file preview / diff on a page now also waits for the pool chunk plus worker init instead of a pre-warmed pool; FilePreview's existing 'wait f | Follow-up already noted by the implementer: SplitWorkspaceRoute chunk (620 KB) still carries handlebars/source-map via @bb/templates and preact via @pierre/trees; workspace-checkou - Wire/contract: None. No server/daemon wire, host RPC, or protocol changes; HOST_DAEMON_PROTOCOL_VERSION unchanged. Plugin runtime shim slot `pierreDiffsReact` keeps the same export names; FileDiff/File/MultiFileDiff/PatchDiff/UnresolvedFile/CodeView are now gated wrappers, WorkerPoolContextProvider is a host passthrough and useWorkerPool returns the host pool (plugin design 5.5: host owns the pool). check-bundle > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…ed loads (A3, B23) (#1896) ## What was wrong - Every running plugin's app bundle (about 3 MB unminified JS plus about 780 KB CSS across the default set) started importing as soon as `/system/config` resolved, all at once via `Promise.all`, each injecting its own `<link rel=stylesheet>` on arrival. On a phone this parse/eval and the dozen style invalidations landed in the same window in which the route chunk was still downloading, so first route content painted late. (Audit finding A3.) - The workflows composer banner called `workflowActiveRuns` once per second on every open thread for as long as it was mounted, whether the thread had a run and whether the tab was visible. (Audit finding B23.) ## What changed - `usePluginFrontendBoot` waits for system config, then for the first route content to commit (`RouteContentPaintSignal`, a sibling of the lazy routes inside their Suspense boundary) plus an idle slot (`requestIdleCallback`, or two animation frames on WebKit), bounded by a 1.5 s timeout. A `/plugins/:pluginId/...` route boots as soon as config resolves because the plugin is the page there. - `reconcilePluginFrontends` imports at most three bundles at a time. The plugin that owns the current panel route goes first, then ascending bundle size. The server now reports `jsBytes` per app bundle (`pluginAppStateSchema`, `GET /api/v1/plugins`). - Plugin stylesheet insertions coalesce into one animation frame (`createBatchedPluginCssApplier`); removals stay synchronous and cancel a pending insertion. The pagehide teardown wiring is untouched. - Workflows: the service publishes a `workflow-runs` realtime signal for the origin thread on run create, claim, settle, and cancel. The banner subscribes and refreshes on a matching signal. Banner and preview directive poll once per second only while a run is active (or the last fetch errored) and `document.visibilityState` is not hidden, with one catch-up refresh when the tab or the realtime connection comes back. ## How you verified - New tests (fail before, pass after): `apps/app/src/lib/plugin-frontend-boot-schedule.test.ts` (paint+idle vs timeout vs cancel), `apps/app/src/hooks/usePluginFrontendBoot.test.tsx` (no boot on config alone; boot after paint+idle; boot at 1.5 s; immediate boot on plugin panel route), `apps/app/src/lib/plugin-frontend-load-order.test.ts` (ordering, max-3 concurrency and lane hand-off, failure isolation, CSS batching/removal), `plugins/workflows/src/app.test.tsx` (idle thread never polls, realtime signal triggers one refresh and polling starts/stops with active runs; hidden document pauses polling and refreshes once on return), `plugins/workflows/src/service-policy.test.ts` (signal published on start/claim/cancel, not on a no-op stop), `apps/server/test/services/plugins/plugin-app-bundle.test.ts` (jsBytes equals dist/app.js size). - `pnpm exec turbo run typecheck` for @bb/app, @bb/server, @bb/server-contract, @bb/templates, @bb/cli, @bb/sdk, bb-plugin-workflows: pass. `pnpm exec turbo run lint --filter=@bb/app`: 0 errors, no warnings in touched files. `pnpm exec turbo run build --filter=@bb/app` + `node scripts/check-bundle-budget.mjs`: bundle budget OK (449.2 KB br boot). Targeted vitest runs listed above: all pass. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 17 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/plugin-build-minify` (#1895). - Next layer: `bb/mobile-perf/plugin-host-slots` (#1897). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Reviewer notes / follow-ups: The package title mentions a 'pageshow reboot' (audit J5: tear down plugin frontends only when !event.persisted, and re-boot on a persisted pageshow) but the branch does not implem | Design trade-off to be aware of (not a bug): reconcile now runs 3 lanes over import + setup + content-script mount. A third-party plugin whose bundle import stalls on a bad network | Contract note: /api/v1/plugins app.bundle.jsBytes is required and the browser-side isFrontendBundle guard drops bundles without it. App, SDK/CLI, and server ship together so this i - Wire/contract: GET /api/v1/plugins (and plugin reload/list responses) app.bundle gains a required `jsBytes: number` field (packages/server-contract pluginAppStateSchema, apps/server app-bundle.ts, apps/app isFrontendBundle guard). This is server<->browser only; nothing on the server<->host-daemon wire changed, so HOST_DAEMON_PROTOCOL_VERSION was not bumped. Regenerated tracked artifacts: packages/plugin-sdk/bund > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Plugin frontend bundles were built without minification, and every plugin's
app.csscarried the Tailwind utilities of all of@bb/shared-ui:bb.pluginTailwindContent: ["src/**/*"]fed the whole package glob to the scanner whether or not the plugin imported those components (~110 KB / ~1200 rules per sheet, plus a:rootblock that re-declared the host's semantic token bridge). On phones the raw bytes drive parse time, each stylesheet insertion is a document-wide restyle, and ~17k scoped rules stay resident. (A4)Four first-party provider plugins (claude-code, codex, pi, acp) shipped an app bundle whose only job was to register, through
experimental_providerIcon, an SVG byte-identical to the one the host already vendors inBUILT_IN_BRAND_ICONS: four JS fetches, four CSS fetches, four stylesheet inserts and four icon remounts per page load for no visible change. (H7)What changed
buildPluginAppbuilds withminify: true,legalComments: "none", and takes{ minify };bb plugin devpasses{ minify: false }so stack traces and CSS stay readable while iterating. Server installs andbb plugin buildminify.optimizefrom@tailwindcss/node, the lightningcss pass the host's Vite build uses); minified in production, pretty in dev, same browser-target lowering in both.bb.pluginTailwindContentglobs now only select which dependency files may be scanned; the scan reads their intersection with esbuild'smetafile.inputs, so a plugin pays only for the shared components it bundles. Scan bases are realpath'd because esbuild reports real paths for workspace links.@theme inlinebridge asinline reference: inline tokens are substituted into utilities at compile time, so the:root { --color-*: var(--*) }block was never read by plugin rules. Non-inline tokens still emit.app.tsx/bb.app/ react devDeps from the four provider plugins; updated the provider-icon comment,docs/api_to_audit.md, and the plugin-authoring skill example that pointed at the deleted file.Built-in bundle bytes (raw / gzip), before -> after:
How you verified
packages/plugin-build/src/build-plugin-app.test.ts: minified vs readable artifacts (identifier mangling, license comment dropped, CSS minified/pretty for both utilities and authored CSS); dependency scanning through a symlinked package with a negated pattern (bundled file scanned, glob-only file not, negated file not, plugin's own dir still scanned whole,:roothas the default token and not the bridge). Both fail before the change.apps/cliplugin-build test,apps/serverplugin-app-bundle test, andpackages/plugin-registryvendor test.turbo run typecheckfor @bb/plugin-build, @bb/cli, @bb/server, @bb/app, @bb/plugin-registry and the four provider plugins: pass.turbo run lint --filter=@bb/app: pass.turbo run test: @bb/plugin-build full suite (22 passed, 1 skipped); @bb/cli plugin-build, docs/github official bundle, packaged-plugin-build, plugin-dev-loop (21 passed); @bb/servertest/services/plugins(34 files, 380 passed); @bb/plugin-registry vendor-all-items; @bb/app provider-icon test.apps/server/scripts/copy-builtin-plugins.tsbefore and after for the byte table above.Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue).
Stack context
Layer 16 of 22 in the
bb/mobile-perf/*stack (bottom → top: quick wins first, big rocks last).bb/mobile-perf/pierre-pool-and-route-closure(Gate the pierre worker pool and trim/ratchet the SplitWorkspaceRoute closure (A2, A1) #1894).bb/mobile-perf/plugin-boot-defer(Defer plugin frontend boot past first route paint with bounded, ordered loads (A3, B23) #1896).buildPluginApp(rootDir, bbVersion, toolchain, options?: PluginAppBuildOptions)gained an optional 4th arg (exported type PluginAppBuildOptions from @bb/plugin-build)