Skip to content

Build core thread actions only from the public plugin API - #8054

Merged
ymichael merged 3 commits into
mainfrom
bb/move-core-thread-actions-behind-the-core-contrib-thr_ka3ws6qnhx
Nov 23, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/move-core-thread-actions-behind-the-core-contrib-thr_ka3ws6qnhx

Conversation

@ymichael

@ymichael ymichael commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb's own thread actions (Open in split, Copy link, Pin, Mark read, Notify parent, Rename, Regenerate title, Archive, Delete, New thread in environment) were registered through experimental_threadAction, but from apps/app/src/lib/thread-actions/core-thread-actions.ts, outside the apps/app/src/core-contributions/ boundary. They imported private app modules: getThreadLocationPath for Copy link, appToast for toasts, and showMutationErrorToast for failed requests. So nothing showed that a plugin could build them, and the slot docs' "core uses this too" was only partly true. Two of those reads had no public path at all. Plugins had no way to show bb's failed-request toast. And a plugin's import { toast } from "sonner" reaches bb's toaster only through the runtime shim, which core code bundled into the app never passes through.

What changed

  • The move. The registrations now live in apps/app/src/core-contributions/thread-actions.ts as a default-exported definePluginApp. bb/core-contribution-imports passes with no suppressions. lib/thread-actions/core-thread-actions.ts only collects them into CORE_THREAD_ACTIONS, the same way plugin-slots.ts collects message time.
  • Private imports replaced:
    • getThreadLocationPath → navigate.experimental_threadHref(thread.id), made absolute with new URL(href, location.origin), as that method's JSDoc already describes. One known difference: experimental_threadHref takes only the thread id and reads the project from bb's cache. For a thread bb has not loaded, Copy link now copies /threads/<id>, which redirects to the project route. Main copied the project URL. Every surface checked live had the thread loaded and copied the same URL as main.
    • appToast → toast from sonner, the path the Guide documents for plugins.
    • showMutationErrorToast → new experimental_showErrorToast (below).
    • collectCoreContributionSlots → moved out of the file. The contribution only default-exports its definition.
    • Archive and Delete already went through context.threadRequests.requestArchive/requestDelete (Give plugins bb's Archive and Delete flows, and route core's through them #7961), so they are unchanged.
  • New API: experimental_showErrorToast({ error, fallbackMessage }): void in @get-bb/plugin-sdk/app. It is core's showMutationErrorToast, with the same parameter names.
    • No toast for an AbortError.
    • bb's own title and body for a lifecycle error code.
    • Otherwise the title is fallbackMessage and the description is the server's message for an SDK error. Without a body message, the description is the error's message without the HTTP <status>: prefix.
    • A fixed "Could not reach the server" text for network failures.
    • The JSDoc and the docs/api_to_audit.md entry spell this out, including the trailing-period and "Request failed" cases.
    • Core callers: Mark read/unread, Pin, Notify parent, Regenerate title, Unarchive and the bulk forms.
    • The audit entry lists in-repo callers that can migrate later. None are migrated here, because each migration changes a visible toast:
      • thread-list's hand copy app/ui/mutation-errors.ts;
      • side-chat, push-notifications and drafts, which show error.message, i.e. HTTP 4xx: ....
    • The test harness records calls in inspection.experimental_errorToasts. Guide apiSymbols (host-components card), the bb-plugin-authoring reference (still 500 lines) and the SDK version (0.6.187) are updated.
  • sonner for core contributions. vite-core-plugin-sdk-app.ts (Vite, Vitest and Ladle) now also resolves sonner imported from apps/app/src/core-contributions/ (not tests or stories) to lib/plugin-sonner.ts. That module exports the same createPluginToast instance plugin-frontend.ts hands to plugins, and plugin-frontend.ts now imports it from there, so there is one toast object. The shim calls appToast with no plugin attribution, so core's toasts and notification-center entries are unchanged. createPluginToast no longer captures sonner's toast at module load. It reaches sonner only through the toaster AppToasterView attaches (withSonnerToast, plus readSonnerToasts for getHistory/getToasts, which return nothing before the toaster mounts). That keeps sonner off the boot path even though core's thread actions load at boot.
  • V1 needed no new API. "Open in split" and "New thread in environment" read the compact viewport with useIsCompactViewport from @bb/shared-ui/hooks/use-compact-viewport. That is already public as the registry item use-compact-viewport, which the bundled thread-list plugin vendors, and the boundary lint accepts it. Its value is the slots' isCompactViewport prop. A second SDK hook would have been a parallel public path, so there is none.

How you verified

  • pnpm exec turbo run typecheck lint test --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=@bb/domain --filter=bb-plugin-plugin-api-docs --filter=bb-plugin-bb-guide: green.
  • pnpm exec oxlint -c .oxlintrc.json apps/app/src/core-contributions: 0 findings, no disable comments.
  • ThreadActionsMenu.test.tsx spies on appToast.success while Copy link runs from the core contribution. It only passes if the contribution's sonner import resolves to bb's toaster.
  • Resolver scope, probed directly: sonner → lib/plugin-sonner.ts only for non-test files under src/core-contributions/. It stays raw for *.test.ts, *.stories.tsx, lib/plugin-sonner.ts itself, other lib/ files and look-alike folders. @get-bb/plugin-sdk/app resolution is unchanged.
  • Live, pnpm start:worktree with headless Chrome. The same scripts ran against this branch and against main's build on the same data dir:
    • Menus on the sidebar row, the context menu, the thread header, bulk selection (3 threads, including Notify parent choices and the count labels), the command palette's thread commands, and the compact (390 px) header drawer. All 13 captures are identical. Open in split shows at desktop width and is absent at compact width, where New thread in environment appears instead.
    • Action outcomes: Copy link (toast and clipboard URL), Regenerate title (loading toast, then "Failed to regenerate title" with the server's message), notification-center entries, the Pin, Mark read and Archive shortcuts with Undo, Archive from the menu with Undo, Delete with its confirmation, Notify parent → When stuck, and Open in split. All 28 outcomes are identical.
    • The Copy link toast, the Regenerate title error toast and the notification center are pixel-identical between main and the branch.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits November 23, 2026 13:18
Move bb's thread actions into apps/app/src/core-contributions/thread-actions.ts,
where bb/core-contribution-imports allows only what a plugin gets, with no
suppressions. Copy link builds its URL with navigate.experimental_threadHref,
toasts go through sonner, and failed requests through the new
experimental_showErrorToast, which is core's showMutationErrorToast. The
compact-viewport read stays on the public use-compact-viewport registry hook.

Inside the app bundle sonner is the raw package, while plugins get bb's
toaster through the runtime shim. bb:core-plugin-sdk-app now resolves sonner
for core-contribution source (not tests or stories) to that same shimmed
toast, which plugin-frontend now shares.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
plugin-sonner.ts statically imported sonner to build the plugin toast, and
core's thread actions load at boot, so sonner landed in the boot payload
and failed the bundle budget. createPluginToast now reaches sonner only
through the toaster it attaches when it mounts: raw and custom toasts run
through withSonnerToast's attached toast, and getHistory/getToasts read it
through readSonnerToasts, returning nothing before the toaster mounts.
plugin-sonner.ts exports only that toast.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/move-core-thread-actions-behind-the-core-contrib-thr_ka3ws6qnhx branch from ad530e4 to ea41392 Compare November 23, 2026 21:20
@ymichael
ymichael merged commit a88df31 into main Nov 23, 2026
52 checks passed
@ymichael
ymichael deleted the bb/move-core-thread-actions-behind-the-core-contrib-thr_ka3ws6qnhx branch November 23, 2026 21:58
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