← reports

#6320 · Runtime SDK dependencies are incorrectly normalized as development-only

BugPriority: MediumEffort: LowpluginscliIssue #63202026-10-26

Trusted main base: 3540a699e29034b53da32bb7efa6f5b4055209eb

Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro

1. TL;DR

The SDK pinning command treats every SDK runtime dependency as an authoring-only dependency. A plugin that needs a real SDK host export builds successfully with its SDK installed, but pin synchronization moves that dependency to devDependencies. In a clean production layout without development packages, the same host build then fails while the actual source CLI's types --check exits successfully. This is reproduced for both the provider-bridge subpath and the native-roots host contract on trusted main, and repeated in a second clean checkout by the same investigator. Restoring the existing local SDK makes both builds pass again.

2. Claims vs findings

ClaimFindingEvidence
SDK runtime dependencies are moved to development dependencies.VerifiedThe real setPluginSdkPin helper removes the runtime declaration in both cases.
A correct runtime declaration is rejected, but the resulting broken layout passes the check.VerifiedActual source CLI exits 1 before synchronization and 0 after the SDK is absent.
Host bridge and non-stub host imports need a plugin-local SDK.VerifiedReal host builder passes with the local SDK, fails without it, and passes when it is restored.
The Git installer omits development dependencies.Verified in sourceTrusted installer passes --omit=dev and --omit=optional to npm.
Installing directly from Git on macOS produces the reported result.Not executed end to endThis Linux reproduction directly constructs the equivalent clean production layout; it does not install an external plugin, fetch an npm SDK, or run the desktop app.

3. Environment

4. Minimal reproduction

  1. Clone the trusted repository and install its frozen dependencies.
  2. Build the SDK runtime and CLI using the filtered Turbo command below.
  3. Save the complete inline script below as /tmp/reproduce-6320.mjs.
  4. Run the reproduction. It makes two new plugins with valid package metadata, a server entry, and a host re-export from a real SDK runtime subpath. It links the existing local SDK, verifies a successful host build, executes the actual source CLI check, and calls the same mutation helper used by the CLI.
  5. It checks that synchronization moves the SDK, removes the local installation to represent a clean omit-dev install, and confirms that the check succeeds although the host builder fails. Re-linking the existing SDK is a positive control.
  6. Run with --assert-fixed to exercise the expected-behavior regression assertion. On unchanged main it exits 1 with the assertion shown below. Normal reproduction exits 0 only after proving both failures and both restoration controls.
git clone https://github.com/get-bb/bb.git bb-6320
cd bb-6320
git checkout 3540a699e29034b53da32bb7efa6f5b4055209eb
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk --filter=@bb/cli

node --conditions=source --import ./node_modules/tsx/dist/loader.mjs /tmp/reproduce-6320.mjs "$PWD"
node --conditions=source --import ./node_modules/tsx/dist/loader.mjs /tmp/reproduce-6320.mjs "$PWD" --assert-fixed

VERIFY=$(mktemp -d)
git worktree add --detach "$VERIFY/checkout" 3540a699e29034b53da32bb7efa6f5b4055209eb
cd "$VERIFY/checkout"
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk --filter=@bb/cli
node --conditions=source --import ./node_modules/tsx/dist/loader.mjs /tmp/reproduce-6320.mjs "$PWD"

Expected: An aligned SDK declaration required by a host runtime import is accepted in dependencies; synchronizing it preserves a buildable production layout. Actual: The original runtime declaration is rejected, normalization moves it, and the check then accepts a layout the builder cannot resolve.

Complete reproduction / regression script

import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";

const checkout = resolve(process.argv[2] ?? process.cwd());
const assertFixed = process.argv.includes("--assert-fixed");
const source = async (relativePath) => import(pathToFileURL(join(checkout, relativePath)).href);
const { setPluginSdkPin } = await source("packages/templates/src/plugin-scaffold.ts");
const { buildPluginHost } = await source("packages/plugin-build/src/build-plugin-host.ts");
const { resolvePluginBuildToolchain } = await source("packages/plugin-build/src/toolchain.ts");
const sdkRoot = join(checkout, "packages/plugin-sdk");
const { version: sdkVersion } = JSON.parse(await readFile(join(sdkRoot, "package.json"), "utf8"));
const toolchain = await resolvePluginBuildToolchain(join(checkout, "packages/plugin-build/.unused-toolchain"));
const scratch = await mkdtemp(join(tmpdir(), "bb-6320-check-"));

async function installLocalSdk(directory) {
  await mkdir(join(directory, "node_modules/@get-bb"), { recursive: true });
  await symlink(sdkRoot, join(directory, "node_modules/@get-bb/plugin-sdk"), "dir");
}

function cliCheck(directory) {
  const result = spawnSync(process.execPath, ["--conditions=source", "--import", join(checkout, "node_modules/tsx/dist/loader.mjs"), join(checkout, "apps/cli/src/index.ts"), "plugin", "types", "--check", directory], {
    encoding: "utf8",
    env: { ...process.env, BB_CLI_REEXEC: "1", BB_CLI_ERROR_LOG: "0", BB_SERVER_URL: "http://127.0.0.1:1" },
  });
  console.log(`types --check exit=${result.status}`);
  console.log((result.stdout + result.stderr).trim());
  assert.equal(result.error, undefined);
  return result.status;
}

try {
  for (const [name, modulePath, symbol] of [
    ["bridge", "@get-bb/plugin-sdk/provider-bridge", "PROVIDER_BRIDGE_EXPORT_NAME"],
    ["native-roots", "@get-bb/plugin-sdk/host", "experimental_nativeRootsHostContract"],
  ]) {
    console.log(`CASE ${name}; sdk=${sdkVersion}`);
    const directory = join(scratch, name);
    await mkdir(directory);
    await writeFile(join(directory, "package.json"), JSON.stringify({
      name: `bb-plugin-contract-${name}`,
      version: "1.0.0",
      type: "module",
      bb: {
        name: "Contract build verification",
        description: "Checks an SDK runtime export through the host builder.",
        branding: { icon: "Cpu" },
        server: "./server.ts",
        host: "./host.ts",
      },
      dependencies: { "@get-bb/plugin-sdk": sdkVersion },
    }, null, 2));
    await writeFile(join(directory, "server.ts"), "export default () => undefined;\n");
    await writeFile(join(directory, "host.ts"), `export { ${symbol} as default } from ${JSON.stringify(modulePath)};\n`);
    await installLocalSdk(directory);
    await buildPluginHost(directory, "0.0.0-verification", toolchain);
    console.log("SDK in dependencies, installed locally: host build PASS");
    const checkBefore = cliCheck(directory);
    if (assertFixed) {
      assert.equal(checkBefore, 0, "an aligned SDK required by a runtime import must be accepted in dependencies");
      await setPluginSdkPin({ rootDir: directory, sdkVersion });
      const synchronized = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
      assert.equal(synchronized.dependencies?.["@get-bb/plugin-sdk"], sdkVersion);
      continue;
    }
    assert.equal(checkBefore, 1);
    const pending = await setPluginSdkPin({ rootDir: directory, sdkVersion, dryRun: true });
    assert.equal(pending?.movedFromDependencies, true);
    await setPluginSdkPin({ rootDir: directory, sdkVersion });
    const changed = JSON.parse(await readFile(join(directory, "package.json"), "utf8"));
    assert.equal(changed.dependencies?.["@get-bb/plugin-sdk"], undefined);
    assert.equal(changed.devDependencies["@get-bb/plugin-sdk"], sdkVersion);
    console.log("pinning result: SDK removed from dependencies and placed in devDependencies");
    await rm(join(directory, "node_modules"), { recursive: true, force: true });
    console.log("clean production layout: dev-only SDK absent (no registry install)");
    assert.equal(cliCheck(directory), 0);
    let buildFailure;
    try {
      await buildPluginHost(directory, "0.0.0-verification", toolchain);
    } catch (error) {
      buildFailure = error;
    }
    assert.ok(buildFailure, "host build unexpectedly passed without the required SDK");
    assert.match(buildFailure.message, /Could not resolve.*provider-bridge|not installed for this plugin/);
    console.log(`production host build FAIL: ${buildFailure.message.split("\n").at(-1).replaceAll(scratch, "<scratch>")}`);
    await installLocalSdk(directory);
    await buildPluginHost(directory, "0.0.0-verification", toolchain);
    console.log("control: reinstalling existing local SDK restores host build PASS");
  }
  console.log(assertFixed ? "PASS: runtime SDK placement contract holds" : "REPRODUCED: a clean types check accepts both broken production layouts");
} finally {
  await rm(scratch, { recursive: true, force: true });
}

First run: observed output

CASE bridge; sdk=0.6.80
SDK in dependencies, installed locally: host build PASS
types --check exit=1
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
Move "@get-bb/plugin-sdk" from dependencies to devDependencies — bb provides its runtime (`bb plugin types` does it for you).
pinning result: SDK removed from dependencies and placed in devDependencies
clean production layout: dev-only SDK absent (no registry install)
types --check exit=0
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
The declarations are in node_modules/@get-bb/plugin-sdk/bundled-types/ — read them for exact signatures.
✘ [ERROR] Could not resolve "@get-bb/plugin-sdk/provider-bridge"

    host.ts:1:55:
      1 │ ...EXPORT_NAME as default } from "@get-bb/plugin-sdk/provider-bridge";
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@get-bb/plugin-sdk/provider-bridge" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

production host build FAIL: host.ts:1:55: ERROR: Could not resolve "@get-bb/plugin-sdk/provider-bridge"
control: reinstalling existing local SDK restores host build PASS
CASE native-roots; sdk=0.6.80
SDK in dependencies, installed locally: host build PASS
types --check exit=1
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
Move "@get-bb/plugin-sdk" from dependencies to devDependencies — bb provides its runtime (`bb plugin types` does it for you).
pinning result: SDK removed from dependencies and placed in devDependencies
clean production layout: dev-only SDK absent (no registry install)
types --check exit=0
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
The declarations are in node_modules/@get-bb/plugin-sdk/bundled-types/ — read them for exact signatures.
✘ [ERROR] "@get-bb/plugin-sdk/host" is not installed for this plugin (no node_modules/@get-bb/plugin-sdk); a host entry that imports experimental_nativeRootsHostContract needs the SDK as a dependency [plugin provide-public-host-sdk-runtime]

    host.ts:1:64:
      1 │ ...ativeRootsHostContract as default } from "@get-bb/plugin-sdk/host";
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~~~~~

production host build FAIL: host.ts:1:64: ERROR: [plugin: provide-public-host-sdk-runtime] "@get-bb/plugin-sdk/host" is not installed for this plugin (no node_modules/@get-bb/plugin-sdk); a host entry that imports experimental_nativeRootsHostContract needs the SDK as a dependency
control: reinstalling existing local SDK restores host build PASS
REPRODUCED: a clean types check accepts both broken production layouts

Expected-behavior regression: failure on unchanged main

CASE bridge; sdk=0.6.80
SDK in dependencies, installed locally: host build PASS
types --check exit=1
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
Move "@get-bb/plugin-sdk" from dependencies to devDependencies — bb provides its runtime (`bb plugin types` does it for you).
node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

AssertionError [ERR_ASSERTION]: an aligned SDK required by a runtime import must be accepted in dependencies

1 !== 0

    at <anonymous> (<report-workdir>/reports/issues/6320/repro/reproduce.mjs:63:14) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: 1,
  expected: 0,
  operator: 'strictEqual',
  diff: 'simple'
}

Node.js v22.19.0

This is a non-visual build-time defect; no screenshots are applicable. The public report intentionally embeds the complete script and output rather than publishing standalone test or log files.

5. Root cause

Normalization has no runtime-dependency exception

planManifest, lines 320–341 decides whether to move the SDK solely from its declaration in dependencies. It does not inspect entries or imports. An exact version does not protect a runtime declaration from being moved.

  const declaredPin = readSdkPinFrom(manifest);
  const pin =
    declaredPin.version === sdkVersion
      ? null
      : { from: declaredPin.version, to: sdkVersion };
  const movedFromDependencies = declaredPin.inDependencies;
  if (pin !== null || movedFromDependencies) {
    if (movedFromDependencies) {
      const deps = asRecord(manifest.dependencies);
      delete deps["@get-bb/plugin-sdk"];
      if (Object.keys(deps).length === 0) {
        delete manifest.dependencies;
      } else {
        manifest.dependencies = deps;
      }
    }
    manifest.devDependencies = insertDependency(
      asRecord(manifest.devDependencies),
      "@get-bb/plugin-sdk",
      sdkVersion,
    );
  }

setPluginSdkPin is the shared mutation/dry-run path. The CLI check and write actions use this planner; a null plan is treated as success without checking whether a required runtime SDK is present.

Production installation and bundling disagree with that assumption

The Git production installer omits development packages:

  await runInstallCommand("npm", [
    "install",
    "--prefix",
    rootDir,
    "--ignore-scripts",
    "--omit=dev",
    "--omit=optional",
    "--no-audit",
    "--no-fund",
  ]);

The host builder SDK shim boundary supplies the root SDK shim and only limited host fallbacks; it does not supply arbitrary provider-bridge runtime code. The native-roots contract is outside the host fallback export set, so its absence produces the dependency diagnostic observed above. Server SDK subpath resolution likewise bundles real subpath implementations from the plugin's own SDK rather than treating all subpaths as host-provided runtime.

The authoring guide's runtime dependency exception explicitly distinguishes these real runtime imports from stub-only host entries. The bug is in generic manifest normalization, not a missing provider registration or invalid import. Git history attributes the unconditional move to e6b7724fae; later edits at the recorded main base still retain it.

6. Proposed fix and safety decision

Make SDK dependency placement consistent with the builder's runtime-import contract: preserve or select dependencies for real runtime SDK subpaths, while retaining devDependencies for authoring-only/stubbed usages. Use one placement policy for check and write, cover re-exports and transitive local imports, and add both runtime-import and stub-only controls. A builder-level fallback to BB's SDK is a different packaging/design choice and should not be introduced opportunistically.

No automatic fix PR: Repairing SDK dependency placement changes plugin dependency packaging, which this SlopCop rule explicitly excludes from its simple-fix allowance. No production change, dependency change, branch, push, or PR was made in get-bb/bb. The target repository's diff is empty (0 changed text lines); no binary changes exist. No open PR linking #6320 was found in issue cross-references or a repository open-PR search.

7. Verification

The same investigator repeated the reproduction in a second, clean detached checkout at 3540a699e29034b53da32bb7efa6f5b4055209eb, with a separate frozen install, targeted build, and freshly created temporary fixture directory. The source CLI's re-execution override is explicitly disabled with BB_CLI_REEXEC=1, and CLI error logging is disabled. The initial harness was corrected to avoid an inherited launcher redirect to the installed CLI; only the corrected source-CLI runs below support this verdict. No clean-run finding required a change to the root-cause conclusion. This is a repeat check by the same investigator, not independent verification.

Second command: node --conditions=source --import ./node_modules/tsx/dist/loader.mjs /tmp/reproduce-6320.mjs "$PWD", run from the second checkout. Exit: 0.

CASE bridge; sdk=0.6.80
SDK in dependencies, installed locally: host build PASS
types --check exit=1
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
Move "@get-bb/plugin-sdk" from dependencies to devDependencies — bb provides its runtime (`bb plugin types` does it for you).
pinning result: SDK removed from dependencies and placed in devDependencies
clean production layout: dev-only SDK absent (no registry install)
types --check exit=0
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
The declarations are in node_modules/@get-bb/plugin-sdk/bundled-types/ — read them for exact signatures.
✘ [ERROR] Could not resolve "@get-bb/plugin-sdk/provider-bridge"

    host.ts:1:55:
      1 │ ...EXPORT_NAME as default } from "@get-bb/plugin-sdk/provider-bridge";
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@get-bb/plugin-sdk/provider-bridge" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

production host build FAIL: host.ts:1:55: ERROR: Could not resolve "@get-bb/plugin-sdk/provider-bridge"
control: reinstalling existing local SDK restores host build PASS
CASE native-roots; sdk=0.6.80
SDK in dependencies, installed locally: host build PASS
types --check exit=1
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
Move "@get-bb/plugin-sdk" from dependencies to devDependencies — bb provides its runtime (`bb plugin types` does it for you).
pinning result: SDK removed from dependencies and placed in devDependencies
clean production layout: dev-only SDK absent (no registry install)
types --check exit=0
This plugin uses the npm package @get-bb/plugin-sdk; pin is 0.6.80, host is 0.6.80.
The declarations are in node_modules/@get-bb/plugin-sdk/bundled-types/ — read them for exact signatures.
✘ [ERROR] "@get-bb/plugin-sdk/host" is not installed for this plugin (no node_modules/@get-bb/plugin-sdk); a host entry that imports experimental_nativeRootsHostContract needs the SDK as a dependency [plugin provide-public-host-sdk-runtime]

    host.ts:1:64:
      1 │ ...ativeRootsHostContract as default } from "@get-bb/plugin-sdk/host";
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~~~~~

production host build FAIL: host.ts:1:64: ERROR: [plugin: provide-public-host-sdk-runtime] "@get-bb/plugin-sdk/host" is not installed for this plugin (no node_modules/@get-bb/plugin-sdk); a host entry that imports experimental_nativeRootsHostContract needs the SDK as a dependency
control: reinstalling existing local SDK restores host build PASS
REPRODUCED: a clean types check accepts both broken production layouts

8. Related issues

A bounded repository search for SDK dependency issues did not identify an open duplicate. No issue comments or linked pull requests were present at investigation time. Reports about unrelated import scanning or UI-only dependency trimming were not executed or relied on as proof.

9. Appendix and limits

Validation commands used in addition to the reproduction commands:

pnpm exec turbo run test --filter=@bb/templates -- test/plugin-migrate-layout.test.ts
pnpm exec turbo run test --filter=@bb/plugin-build -- src/build-plugin-host.test.ts
git diff --check
git diff --numstat origin/main

The first unfiltered pnpm exec turbo run build stopped because a workspace plugin reached an SDK host export before its SDK dist existed. The filtered SDK/CLI prerequisite build then passed in both checkouts. This unrelated clean-build ordering limitation was not repaired. Existing template tests explicitly cover moving a generic exact SDK dependency; they do not cover the runtime-import exception demonstrated here.

The reproduction exercises actual source CLI checks, the shared pinning mutation helper, and real host bundling. It does not execute the CLI's npm-registry warning path, install a Git-distributed external plugin, exercise macOS desktop packaging, or run provider sessions. Production omission is a controlled filesystem setup, supported separately by the real installer's trusted source. All issue content was treated as untrusted hypotheses; no supplied scripts, linked branches, patches, binaries, or external issue URLs were executed or fetched.

Public output omits local home directories, host names, credentials, and temporary-directory identifiers.