Skip to content

Stop committing generated modules; turbo generates them - #1943

Merged
SawyerHood merged 2 commits into
mainfrom
bb/organize-generated-templates-thr_wm4wfvgybd
Aug 19, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/organize-generated-templates-thr_wm4wfvgybd

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

Seven derived artifacts were committed: packages/templates/src/generated/* (prompt templates, the plugin-SDK .d.ts embed, the --app starter files), packages/plugin-sdk/bundled-types/*.d.ts, packages/plugin-build/src/generated/plugin-theme.generated.ts and packages/plugin-build/src/runtime-export-manifest.ts. They are pure functions of tracked sources, but they are large files with very long lines (the dts embed is one 628 KB line), and many PRs touch them: 216, 154 and 149 commits in the last three months for the top three. Two concurrent changes to the SDK types conflicted every time. Each one also carried a --check mode wired into typecheck/test to catch staleness.

What changed

  • .gitignore now covers packages/templates/src/generated/, packages/plugin-sdk/bundled-types/ and packages/plugin-build/src/generated/; the files are removed from git (−25 K lines). runtime-export-manifest.ts moves into src/generated/ as runtime-export-manifest.generated.ts.
  • turbo.json gains generator tasks with explicit inputs/outputs:
    • @bb/templates#generate:templates — prompts only, sub-second.
    • @bb/templates#generate:plugin-scaffold — new scripts/generate-plugin-scaffold.mjs (split from generate-templates.mjs): the --app starter files from the committed component registry. Sub-second.
    • @bb/plugin-build#generate — theme CSS + runtime export manifest.
    • @get-bb/plugin-sdk#build:types — the ~20 s rollup dts bundle as its own task; #build now depends on it and builds only the runtime (prepack still runs both for npm publish).
  • The SDK .d.ts is no longer embedded in a generated module. syncPluginTypes (bb plugin types|build|dev on a vendored-layout plugin) loads the declarations at runtime via packages/templates/src/plugin-sdk-dts.ts: the packaged CLI (host-daemon/dist/bb) inlines them through an esbuild define at bundle time; source and dev builds read packages/plugin-sdk/bundled-types from the workspace. So @bb/cli#build — every pnpm bb — never waits for the 20 s dts build.
  • Ordering: @bb/templates#topo and @bb/plugin-build#topo depend on their generators, so only packages that transitively depend on those two are ordered after (and hash) them. Only real consumers depend on the dts bundle: @bb/host-daemon#build (inline), the SDK's own typecheck/test, @bb/cli#test/@bb/templates#test (runtime read), @bb/integration-tests#typecheck (no source condition) and the 25 in-repo plugin typechecks.
  • Removed: every --check mode and staleness test, the --templates flag of scripts/build-node-entry.mjs, and the ad-hoc generator imports in the apps/{cli,server,host-daemon} build scripts. eslint/prettier ignore the generated dirs. Stale .gitignore/.gitattributes entries cleaned.
  • DX: root prepare runs the three cheap generators on pnpm install (~0.8 s) so a fresh clone's editor resolves the imports. Editor resolution of @get-bb/plugin-sdk inside plugins/* needs one turbo run build:types --filter=@get-bb/plugin-sdk; AGENTS.md documents it. docs/cli-guide-and-skill.md updated.
  • packages/plugin-registry/r/ stays committed: it is served from GitHub raw at release tags for npx shadcn add @bb/<name>.

No wire change; HOST_DAEMON_PROTOCOL_VERSION untouched.

How you verified

  • Cold run with every generated dir and dist deleted: pnpm exec turbo run build typecheck lint → 84/84 tasks pass; repeat runs are full cache hits.
  • bb plugin types on a vendored-layout fixture: dev CLI reads the workspace declarations and fails with a clear message when they are absent; the packaged CLI (host-daemon/dist/bb) works with no workspace on disk (inlined).
  • pnpm exec turbo run test --filter=@bb/templates --filter=@get-bb/plugin-sdk --filter=@bb/cli --filter=@bb/plugin-build → all pass; apps/server plugin-install.test.ts passes.
  • Generated output is byte-identical to the previously committed files except the "Generated by" header line.
  • turbo run dev --dry shows @bb/{app,server,host-daemon}#dev depend on the cheap generators only.

Fixes #

AGENT GENERATED: by Claude Opus 5

@bb-slop-cop

bb-slop-cop Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request now. I will check security, code quality, performance, architecture, and the end-to-end build path.

The prompt templates, the plugin SDK bundled .d.ts, the scaffold embeds,
the plugin theme CSS and the runtime export manifest were committed
derivatives of tracked sources. They are large single-line blobs that
merge-conflict on almost every concurrent change (216, 154 and 149
commits in three months for the top three).

They are now gitignored and produced by turbo tasks with explicit
inputs/outputs: @bb/templates#generate:templates,
@bb/templates#generate:plugin-scaffold, @bb/plugin-build#generate and
@get-bb/plugin-sdk#build:types. `topo` depends on the cheap generators so
every build/typecheck/test task is ordered after them; only real
consumers depend on the 20s dts bundle. All --check modes, staleness
tests and ad-hoc generator calls in build scripts are removed.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/organize-generated-templates-thr_wm4wfvgybd branch from f99d7ba to c3ce10f Compare August 19, 2026 19:23
Comment thread turbo.json
"inputs": [
"$TURBO_DEFAULT$",
"$TURBO_ROOT$/packages/*/package.json",
"$TURBO_ROOT$/packages/*/src/**",

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.

🚨 slopcop/review — [P1] Include the shared TypeScript configuration in this task's inputs. packages/plugin-sdk/tsconfig.json extends that configuration, and rollup-plugin-dts consumes it. A shared configuration change can alter declarations without changing this cache key, so Turbo can restore stale output. This broad glob also hashes five ignored generated modules, including downstream scaffold output. Narrow the source inputs and add packages/tsconfig/*.json.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 50ecc2f: @get-bb/plugin-sdk#build:types (and #build) now hash $TURBO_ROOT$/packages/tsconfig/*.json and exclude packages/*/src/generated/** from the source glob.

Comment thread package.json Outdated
"node": ">=22.19.0"
},
"scripts": {
"prepare": "turbo run generate:templates generate --filter=@bb/templates --filter=@bb/plugin-build --output-logs=errors-only --summarize=false",

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.

🚨 slopcop/review — [P2] This hook creates only the cheap source outputs. It leaves packages/plugin-sdk/bundled-types absent, although package exports and plugin TypeScript paths reference that ignored directory. A fresh install therefore leaves editor imports unresolved until a specific Turbo consumer runs. Add an editor preparation path or another fast fallback for these declarations.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Partly addressed in 50ecc2f. The SDK declarations are no longer needed by the CLI build at all: syncPluginTypes reads packages/plugin-sdk/bundled-types at runtime in dev (the packaged CLI inlines them at bundle time), so bb plugin new and every other pnpm bb path work on a fresh install. What remains is editor resolution of @get-bb/plugin-sdk inside plugins/* before the first typecheck. I did not add the ~20 s rollup build to prepare on purpose (it would run on every pnpm install); AGENTS.md now documents the one-off command. Open to adding it to prepare if the install-time cost is acceptable.

if (current === content) {
console.log(`Unchanged ${path.relative(pkgRoot, target)}`);
} else {
writeFileSync(target, content);

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.

🚨 slopcop/review — [P2] Write these generated declarations with a temporary sibling and an atomic rename. Independent Turbo processes can run this task and a consumer at the same time. writeFileSync truncates the final file before it replaces the content, so another process can read a partial declaration. Apply the same fix to generate-plugin-theme.mjs, which also writes its final output directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 50ecc2f: both build-bundled-dts.mjs and generate-plugin-theme.mjs now write a temp sibling and rename (the templates generators already did).

Comment thread turbo.json Outdated
"dependsOn": [
"^topo"
"^topo",
"@bb/templates#generate:templates",

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.

🚨 slopcop/review — [P2] Do not attach both global generators to every topo node. The dry graph contains 69 topo tasks, and each one depends on these generators. A prompt, SDK, or shared UI change can therefore invalidate unrelated build, test, and type-check caches. Add generator edges only to actual consumers, or split the transit nodes by generated output.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 50ecc2f: the generator edges moved from the global topo to @bb/templates#topo and @bb/plugin-build#topo. Only packages that transitively depend on those two packages (i.e. can resolve the generated sources) are ordered after the generators; @bb/domain#typecheck etc. no longer depend on them (verified with turbo --dry=json).

@bb-slop-cop bb-slop-cop Bot 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.

🚨 SLOP COP 🚨 · review

Plain English summary: This PR stops storing large generated modules in Git. Turbo now creates them when a task needs them. The approach reduces merge conflicts, but the new task graph has four cache and file-write problems.

I found four issues:

  1. High: The SDK declaration cache omits shared TypeScript configuration. Turbo can restore stale declarations after a configuration change. Its broad source glob also hashes five downstream generated files and causes extra rebuilds.
  2. Medium: A fresh pnpm install does not create the ignored SDK declarations. Editors can report unresolved plugin SDK imports until a specific Turbo task runs.
  3. Medium: Two generators write final files directly. Concurrent Turbo processes can read a declaration or theme module while another process rewrites it.
  4. Medium: All 69 topo tasks depend on both global generators. A prompt, SDK, or shared UI change can invalidate unrelated build, test, and type-check caches.

The generated declarations match the former committed files. The other generated modules only change their source comments. Six affected package type checks passed. The CLI, server, and host daemon builds passed. The application and Settings page loaded without browser console errors.

The plugin SDK and template tests passed. One unchanged plugin CSS test failed twice. The test source and generated theme match the parent commit, so I did not attribute that failure to this PR.

The generator split is reasonable. The architecture can improve by adding edges only to real consumers and by sharing the existing atomic-write pattern. The existing duplicated shim list remains a drift risk, but this PR does not increase that duplication.

This run reviewed f99d7ba9. The PR advanced during the review, but the newer revision did not change the four affected files.

- The plugin-SDK declarations are no longer embedded in a generated
  module. `syncPluginTypes` loads them at runtime: the packaged CLI
  (host-daemon/dist/bb) inlines them through an esbuild `define` at
  bundle time; source and dev builds read packages/plugin-sdk/
  bundled-types from the workspace. `@bb/cli#build` (every `pnpm bb`)
  no longer waits for the 20s rollup dts build, which timed out the
  source-CLI wrapper test on CI.
- Generator edges hang off `@bb/templates#topo` / `@bb/plugin-build#topo`
  instead of every package's `topo`, so a prompt or theme change no
  longer invalidates unrelated caches.
- `@get-bb/plugin-sdk#build:types` hashes packages/tsconfig/*.json and
  excludes generated modules from its source glob.
- build-bundled-dts.mjs and generate-plugin-theme.mjs write through a
  temp sibling + rename.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood merged commit 328d5a8 into main Aug 19, 2026
12 checks passed
@SawyerHood
SawyerHood deleted the bb/organize-generated-templates-thr_wm4wfvgybd branch August 19, 2026 19:50
erik668 added a commit to erik668/bb that referenced this pull request Aug 30, 2026
…ow bridge

Resolves two conflicts against upstream:
- packages/templates/src/generated/templates.generated.ts: upstream stopped
  committing generated modules (get-bb#1943); take the deletion, turbo regenerates it.
- plugins/memory/app.tsx: keep this branch's Pick<MemoryRecordContract> alias and
  hand-rolled parsers. Upstream's PluginRpcResult alias would redeclare
  MemoryRecord, and the merged-in candidate parsers depend on isRecord/parseMemory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant