Skip to content

Read plugin imports from tokens, not raw source text - #5518

Merged
ymichael merged 1 commit into
mainfrom
fix/5326-sdk-import-scanner
Oct 14, 2026
Merged

ymichael merged 1 commit into
mainfrom
fix/5326-sdk-import-scanner

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

experimental_scanPublicSdkOnly found import specifiers with regular expressions over the raw file text (from "…", import(…), require(…)). The regexes could not tell code from strings, comments, or property names. So method definitions ({ import(x) {} }), property calls (f.import(x)), test titles (it("after a confirmed import", …)), comments, and source code stored in template literals were all reported as module imports. Valid plugin tests failed the public-SDK dependency gate, and authors had to rename methods and titles to get past it. See #5326 and the slop-cop report.

What changed

  • New packages/plugin-sdk/src/testing/module-references.ts. A small, dependency-free tokenizer that skips comments, strings, template literals, regex literals, and (in .tsx) JSX text. From the remaining tokens it reads:

    • import … from "x", import "x", and export … from "x" declarations
    • import() and require() calls, except property accesses (.import, ?.import, #import) and method definitions

    It needs no parser dependency. The earlier bot candidate pulled one in and broke the bundled ESM testing entrypoint (Dynamic require of "fs").

  • public-sdk-only.ts. The two regexes are replaced with moduleReferences(). Classification is unchanged: private-package, outside-allowlist, outside-package, dynamic-specifier. Two caller-visible differences:

    • violations are listed in source order instead of all dynamic-specifier entries last
    • a non-literal argument is reported in full instead of truncated at its first )
  • docs/api_to_audit.md. Audit item 2 for this API now describes the tokenizer and its remaining heuristics: a / after ) is read as division, and a < in .tsx is tried as JSX and falls back when no closing tag matches.

  • Version bump. Plugin SDK 0.6.47, so the fix publishes to npm.

  • No wire, protocol, CLI, or data-model changes.

How you verified

  • Issue repro against the built dist/testing/index.js. The method, property-call, property-literal-call, and test-title cases now return []. realImports still reports @bb/db (private-package) and unapproved-package (outside-allowlist). Published 0.6.43 still shows all four false positives.
  • Two new tests in public-sdk-only.test.ts.
    • The false-positive case covers method and property calls, interface methods, object keys, regexes, comments, strings, templates, a test title, and JSX text with apostrophes and //. Against the old scanner it fails with 18 violations.
    • The real-import case covers import type, default plus named, namespace, side-effect, import = require, export … from, export * as, typeof import(), a ternary import(spec), import() inside a template substitution, require in an array, and import()/require() inside JSX attributes and children. Against the old scanner it fails only on result order.
  • Turbo checks. pnpm exec turbo run typecheck test build --filter=@get-bb/plugin-sdk --filter=bb-plugin-echo-provider passes: SDK 371 tests, echo-provider 15 tests.
  • Old vs new scanner over every package in the repo (102 packages, 6,081 files, about 2.1 s for the new scan).
    • The new scanner drops 417 old results. I checked the suspicious ones by hand: all were strings, comments, or source text held in template literals, such as test fixtures written to disk and String.raw extension source. None was a real import.
    • The 22 results only the new scanner reports are the same non-literal import()/require() calls, now showing the full argument text.

Fixes #5326

AGENT GENERATED

🤖 Generated with Claude Code

experimental_scanPublicSdkOnly matched import specifiers with regexes over
the raw file, so method names (`{ import(x) {} }`), property calls
(`f.import(x)`), comments, strings, template literals, and JSX text were
reported as imports. A small dependency-free tokenizer now skips those and
reads only import/export declarations and import()/require() calls.

Fixes #5326

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 1859b76 into main Oct 14, 2026
47 of 48 checks passed
@ymichael
ymichael deleted the fix/5326-sdk-import-scanner branch October 14, 2026 21:54
ymichael added a commit that referenced this pull request Oct 14, 2026
…#4992)

## Human comments

## What was wrong

BB command and plugin documentation was duplicated across guide
chapters, shipped skills, and repository docs. Updating one surface
could leave conflicting instructions elsewhere, while completed plans
and historical audits obscured current references.

## What changed

- Make `bb guide` the core CLI manual and reduce the `bb-cli` skill to
chapter routing and agent guidance.
- Move plugin-specific commands and settings into their owning skills,
including ACP configuration, notifications, sidebar preferences, and
workflows.
- Remove the standalone automations chapter and route `bb guide
automation` and `automations` to the plugins chapter.
- Split the threads chapter by task so an agent reads only what it
needs: `threads` (spawn, hand off, fork, edit), `thread-inspection`
(list, inspect, wait, open), `thread-messaging` (tell, metadata,
interactions, queue), and `thread-lifecycle` (stop, clear, compact,
retry, archive, delete). Each is 90–175 lines instead of one 530-line
page; aliases such as `queue`, `retry`, and `inspect` route to the right
chapter.
- Consolidate plugin API guidance and trim repository docs to living
references, removing completed plans, obsolete audits, and unused
assets.
- Update documentation expectations and construct workflow test fixtures
from the actual settings defaults.

The branch is rebased onto `origin/main`, preserving its newer
documentation. Runtime changes are limited to guide chapter routing and
aliases; there are no daemon wire changes.

## How you verified

- Rebased onto `origin/main` at 1859b76. Main's newer guidance went
into the consolidated destinations, including:
- Settings: `keepHistoryAfterContextClear`, onboarding replay and `bb
project discover`, `bb settings cli-command`, `bb settings usage
--refresh`, the `timelinePush` experiment, and the always-on navigation
rail.
- Plugins: `bb plugin prune`, background plugin updates, and `bb
marketplace add --subdirectory`.
- Threads and providers: `bb thread commands`/`options`, `usage.cost`,
push-notification levels, `bb provider-retry explain`, and OpenCode
agents as ACP modes.
- Plugin API: `environment.removed`, `experimental_saveFile`, the
tokenizer-based `experimental_scanPublicSdkOnly` (#5518),
`experimental_optionLabels`, the provider bridge's 50 ms text batching,
and its session-option state kinds.
- Removed documentation of the sidebar navigation and header plugin APIs
that main deleted (#5229).
- Deduplicated `docs/configuration.md` (one statement per setting or
plugin), folded the dated sections of `docs/ci-performance.md` into its
topical sections, and restored the core-callers notes in
`docs/api_to_audit.md` that AGENTS.md requires.
- Built the CLI and ran `bb guide` with each new chapter, the
`queue`/`retry`/`inspect`/`messaging` aliases, and an unknown chapter.
- Checked that inbound anchor links to the rewritten docs still resolve.
- `pnpm exec turbo run test --filter=@bb/templates
--filter=@get-bb/plugin-sdk --filter=@bb/sdk
--filter=bb-plugin-workflows`: passed.
- `pnpm exec turbo run test --filter=@bb/cli --filter=@bb/server --
src/__tests__/command-output/guide.test.ts
src/__tests__/plugin-guide-docs.test.ts
test/services/plugins/plugin-authoring-docs.test.ts`: passed.
- `oxfmt --check` on every changed Markdown file: clean.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: qa <qa@x>
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.

Plugin SDK import scanner treats property methods and test titles as module imports

1 participant