Skip to content

Resolve and open Markdown links in one place - #6756

Merged
ymichael merged 7 commits into
mainfrom
markdown-link-resolver
Nov 2, 2026
Merged

ymichael merged 7 commits into
mainfrom
markdown-link-resolver

Conversation

@ymichael

@ymichael ymichael commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Every Markdown surface (timeline messages, file previews, plugin Markdown, plugin-embedded ThreadChat) built its own link routing, and each one left out a different piece. File previews had no external-link handler, so links did nothing (#3395). Plugin chats outside the thread view had no file-link handler, so relative links resolved against the app origin (#4438). In-page #fragment links opened a new tab of bb (#6274). Cmd/Ctrl+click on web links was swallowed into the in-app browser (#2288). The Docs file opener ignored the thread's machine for host files (#4480). Behind those sat three copies of "which file does this path mean", three copies of "act on it", and four wrappers around useLocalOpenTargets, plus timeline props threaded through four layers.

What changed

  • One link resolver and click handler (components/ui/markdown-link-target.ts) used by every MarkdownPreview:
    • In Markdown file previews, #fragment links scroll to the matching heading or element id inside the same preview. Headings get GitHub-style ids, and targets keep a top scroll margin so sticky file headers don't cover them. Elsewhere, including timeline messages, headings get no ids and #fragment links render as plain text: in a collapsed message the jump scrolled the clipped message box and fought the timeline's pin to the bottom.
    • Modified and middle clicks on web links are left to the platform, so the desktop app sends them to the system browser.
    • A surface with no link handler falls back to the app navigation's openUrl.
  • One file-link path:
    • resolveThreadLocalFileLink returns the standard ExperimentalFileOpenOptions.
    • useLocalFileLinkOpener previews the file, opens editor links in the editor they name, or toasts an error.
    • The thread view, plugin chat, every file preview and plugin documents all use it, so editor links and errors behave the same everywhere.
    • File previews build their own routing from their source (buildMarkdownFileRouting) instead of receiving half-built routing threaded down from the hosting view. Links inside previews now also work on the new-thread screen and in plugin side panels.
  • One editor-target hook: useLiveFileOpenTargets(root) replaces useCanOpenFileExternally, an unused target-based copy, and inline copies in the file link menu and the external-open dispatcher. resolveEnvironmentOpenContext (a second local-or-remote check) is gone.
  • Timeline: the view that renders a thread provides ThreadTimelineNavigation once (thread view, plugin chat). ThreadScreen, the timeline surface, the rows and the message components no longer take onOpenLink, onOpenLocalFileLink or workspaceRootPath. useMessageLinkRouting replaces four copies of the message routing memo.
  • usePanelFiles keeps openFilePreview stable by keying on the scope's fields. Callers pass a fresh scope object every render, which (once file links went through openFilePreview) re-rendered all timeline Markdown on every thread-view render.
  • Docs plugin: host-file sources resolve their machine from environmentId.
  • Dead code removed: openHostFile (no longer called by core), markdown-document-link-routing.ts, markdown-message-link-routing.ts, environment-file-links.ts.

Not changed:

How you verified

  • Turbo checks: pnpm exec turbo run typecheck lint --filter='...[origin/main]' passes. pnpm exec turbo run test --filter=@bb/app --filter=bb-plugin-simple-notes passes (6,580 and 126 tests). oxfmt --check is clean on the changed files.
  • New tests fail on main and pass here:
    • fragment scrolling;
    • modified-click passthrough;
    • app-navigation fallback for web links;
    • plugin-chat file links outside the thread view;
    • the Docs host-file machine;
    • file-preview link containment;
    • the shared opener's three outcomes.
  • Real app (isolated dev instance, headless Chromium): clicked message links to a workspace file and a host file, a web link, a relative link inside a file preview, #heading and <a id> anchors (they land below the preview header), the "Open in" editor menu, and both links in a plugin page's embedded ThreadChat.
  • Performance, on real data. Two of the longest production threads (798 and 720 turns) were copied into an isolated dev DB. I compared React profiling builds of main and this branch: open the thread, then wheel-scroll back through older messages, recording every commit. Median of 3 runs:
Scenario main render ms this PR render ms main Markdown renders this PR Markdown renders
Claude Code thread, open 122 128 393 (avg, both threads) 320
Claude Code thread, scroll back 339 338 1,960 (avg) 1,924
Codex thread, open 121 89
Codex thread, scroll back 526 536

Render-time differences of this size are within run-to-run noise (±20 ms on open). Render counts are deterministic and are below main. Before the usePanelFiles fix, this branch was 13–39% slower than main, with 513 and 2,615 Markdown renders.

Fixes #2288
Fixes #3395
Fixes #4438
Fixes #4480
Part of #6274

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 7 commits October 30, 2026 21:13
Every Markdown surface built its own link handling, and each optional
piece it left out silently dropped a behaviour. Link classification now
lives in markdown-link-target.ts: one resolver (fragment, app route,
local file, application URL, web URL) and one click handler that every
MarkdownPreview uses.

- In-page #fragment links scroll to the matching heading or element id
  inside the same preview instead of opening a new tab of bb. Headings
  get GitHub-style ids, and targets keep a top scroll margin so a sticky
  file header does not cover them (#6274).
- Cmd/Ctrl/Shift/Alt and non-primary clicks on web links are left to the
  platform, so the desktop app sends them to the system browser (#2288).
- A surface with no link handler opens web links through the app
  navigation host, following the in-app browser preference (#3395).
- Plugin-embedded ThreadChat outside the thread view opens file links as
  workspace or host file previews through app navigation (#4438).
- The Docs opener resolves a host file's machine from its environment
  instead of falling back to the primary host (#4480).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
File links had three classifiers (the thread view's resolver, the plugin
chat fallback, and plugin document routing) and file previews received
half-built link routing threaded down from whichever view hosted them.

- resolveThreadLocalFileLink now returns the app's standard file-open
  request, and the thread view, plugin-embedded ThreadChat and plugin
  documents all open it through the navigation host's openFilePreview.
  This deletes environment-file-links.ts and the thread view's per-kind
  open branches.
- buildMarkdownFileRouting replaces the image-only builder: each file
  preview builds its own image and link routing from its source and opens
  links through app navigation. This deletes buildMarkdownPreviewLinkRouting,
  resolveHostFilePreviewLinkRootPath, markdown-document-link-routing.ts and
  the markdownLinkRouting props on four tab components. File links inside
  previews now also work outside the thread view (root compose and plugin
  panels).
- openHostFile is no longer called by core, so it is removed from
  usePanelFiles and the secondary panel visibility hook.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plugin-embedded ThreadChat had its own copy of the thread view's
file-link handler that passed no editor targets and dropped errors, so
editor links and failures behaved differently there. It now always calls
useOpenThreadLocalFileLink, the same hook the thread view uses, which
resolves the link, opens previews through app navigation, opens editor
links in the named editor, and toasts errors. Inside the thread view the
navigation host is the thread view's own file opener, so the separate
branch that borrowed the thread view's handler is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- useLiveFileOpenTargets(root) is now the one wrapper that resolves a
  file's machine and its editors. It replaces useCanOpenFileExternally,
  the unused target-based copy, and the inline copies in the file link
  menu and the external-open dispatcher. useResolvedLiveFileTarget and
  resolveEnvironmentOpenContext (a second local-or-remote check) are
  gone; resolveLiveFilePath builds absolute paths from a resolved root.
- useLocalFileLinkOpener is the one place a clicked file link is acted
  on: preview, the editor it names, or an error toast.
  useThreadFileLinkOpener wraps it for a thread, and the thread view now
  gets its editors, storage root and link handler from that one call.
- File previews and plugin documents use the same opener, so editor
  links and errors behave the same as in messages. Plugin Markdown only
  loads the opener for documents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
usePanelFiles rebuilt openFilePreview whenever its scope object changed,
and the thread and new-thread views pass a fresh scope object on every
render. Since this branch routes file links through openFilePreview, every
render gave every message new link routing and every Markdown link a new
navigation value, so Markdown re-rendered throughout the timeline.
Keying the callback on the scope's fields fixes it.

Measured with React's profiling build on two real threads (798 and 720
turns), opening the thread then wheel-scrolling back, median of 3 runs:
Markdown renders while opening went 513 -> 320 (main: 393), and while
scrolling back 2615 -> 1924 (main: 1960).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Messages received onOpenLink, onOpenLocalFileLink and workspaceRootPath as
props threaded from the thread view through ThreadScreen, the timeline
surface, the rows and their shared context into each message component,
while plugin panels got the same values from ThreadTimelineNavigation.

- The view that renders a thread now provides ThreadTimelineNavigation
  once: the thread view around its whole tree, the plugin chat around its
  own ThreadScreen. ThreadScreen, the surface, the rows and the message
  components no longer take these props.
- useMessageLinkRouting(threadId) replaces the routing memo repeated in
  three message components and plugin Markdown, and
  markdown-message-link-routing.ts is gone.
- Messages no longer carry a web-link handler: the thread view's handler
  and the app navigation's openUrl are the same opener, which Markdown
  already falls back to.

Render time and render counts on two real long threads are at or below
main with this change (see the previous commit for the method).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In-page # links in timeline messages scrolled clipped collapsed
messages and fought the timeline's bottom pin. #6274 only asks for
file previews, so headings get anchors and # links scroll only where
the routing comes from buildMarkdownFileRouting; elsewhere a # link
renders as plain text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit bbfe431 into main Nov 2, 2026
45 checks passed
@ymichael
ymichael deleted the markdown-link-resolver branch November 2, 2026 17:59
ymichael added a commit that referenced this pull request Nov 2, 2026
## Human comments

## What was wrong

Four app callers kept their own Windows path checks and joins after the
shared host-path parser landed. They disagreed on UNC roots and produced
mixed separators in live file paths.

## What changed

Use the shared parser for folder breadcrumbs and creation, live file
paths, Markdown drive detection, and absolute local path detection.
Preserve Markdown's network-link restrictions and #6756's resolver
changes. No SDK or daemon protocol changes. Net: 52 added, 62 removed.

## How you verified

- `pnpm exec turbo run test --filter=@bb/app -- RemotePathBrowser
useResolvedLiveFileTarget markdown-local-file-link markdown-link`: 65
tests passed.
- `pnpm exec turbo run test --filter=@bb/app -- markdown-file-routing`:
6 tests passed, including #6756's routing coverage.
- `pnpm exec turbo run typecheck lint --filter=@bb/app`: passed; lint
reports 218 warnings, zero errors.
- New Windows/UNC regression cases failed against the original
implementation and pass with the shared parser.

> AGENT GENERATED
ymichael added a commit that referenced this pull request Nov 18, 2026
## Human comments

## What was wrong

Boot JavaScript grew from 349.6 KB to 419.8 KB brotli between #6076
(dae54bd) and f1c5304, measured per module with the same build.
Most of the growth came from features, but the largest piece was a leak.
#6579 had the sidebar updates badge (`useUpdateInventory`) import
`pluginHasUpdateSurfaces` from `PluginUpdatesCard.tsx`. That one helper
put the plugin-management UI, the shared-ui resource list and
`@radix-ui/react-scroll-area` on boot: 19.7 KB brotli. A second leak
came with #6756: `thread-action-registry` imports `useBbNavigate` from
`plugin-navigation-hooks.ts`, which also defined the plugin-only
file-open hook, so the local open-target hooks loaded before first
paint.

While splitting dialogs I also found a bug in `vite-journey-chunks.ts`.
Vite adds `\0vite/preload-helper.js` to `importedIds` for any module
with a dynamic `import()`, with no matching import declaration in the
code. The counts disagreed, so `moduleEdges` fell back to following
every name of every import. Once `ThreadActionsProvider` gained a split,
that pulled the `@bb/client-core` and `@bb/thread-view` timeline code
into the plugin runtime chunk (PluginFrontend +18.5 KB, NewThreadPage
+15 KB).

Boot brotli growth, #6076 → f1c5304 (per-module attribution, brotli
share of each boot chunk):

| Commit / module cluster | Brotli bytes |
|---|---|
| #6579 Settings → Updates: plugin management UI, shared-ui resource
list, `@radix-ui/react-scroll-area` via `pluginHasUpdateSurfaces` |
+19,727 |
| #7133 dependency update: `react-dom` 19.2.4 → 19.3.1 (+ `react`,
`scheduler`) | +7,329 |
| #6002 keyed thread store: `query-tags` keyed store,
`thread-entity-store`, `thread-panel-queries` | +5,824 |
| #6013 / #6519 core tab and message-metadata registrations through the
plugin collector (`plugin-app-registration-collector`, validators) |
+5,249 |
| #7213 single update button: `@radix-ui/react-hover-card`, badge model
| +3,148 |
| #6756 open-target hooks via `plugin-navigation-hooks` | +2,381 |
| #6763 shared rename path: `inline-rename`, rename dialogs | +1,830 |
| #7176 setup-guide telemetry: `onboarding-model` | +1,733 |
| Radix version bumps (`react-collection` and others, excluding
scroll-area and hover-card) | +~3,900 |
| React Compiler memo caches (Nov 15 budget entry) and other
app/shared-ui feature growth | remainder (~19,000) |
| **Total** | **+70,214** |

Shared packages: `@bb/shared-ui` +15.3 KB (mostly the resource list
above), `@get-bb/plugin-sdk` +5.2 KB (the collector),
`@bb/server-contract` +2.0 KB, `@bb/sdk` +1.2 KB, `@bb/domain` +0.1 KB.
Zod was already on boot at #6076 and is unchanged.

## What changed

- `pluginHasUpdateSurfaces` moved from `PluginUpdatesCard.tsx` to
`plugin-status.ts`. The plugin-management UI now loads with Settings and
Tools (−19.7 KB).
- `usePluginCanOpenFileExternally` moved from
`plugin-navigation-hooks.ts` to a new `plugin-file-open-hooks.ts`, still
re-exported by `plugin-sdk-hooks.ts`. The open-target hooks now load
with the thread and compose pages, which already use them (−2.4 KB).
- An earlier version also set `treeshake.manualPureFunctions: ["z"]` to
drop unused zod schemas (−3.6 KB). It is removed. Rolldown matches that
name in every module, minified dependencies included, and also inside
function bodies. In the built app it deleted sonner's
`setSwiping(true)`/`setSwiping(false)` calls (toasts no longer follow a
swipe on touch screens), cmdk's result-sort call, and two `push` calls
in d3-scale's log ticks.
- The project path, project rename and delete, and thread delete and
archive dialogs load behind `defineSplit` preload-tier wrappers that
mount when opened and stay mounted, following `ApplicationUrlDialog`
(−3.1 KB). Nothing in them is visible at first paint.
- `vite-journey-chunks.ts` ignores the preload helper id. The regression
test fails before the fix and passes after.
- `bundle-budget.json`: `splitBoundaries` boot guards for
`PluginUpdatesCard`, `UpdatePluginDialog`, `useLocalOpenTargets` and the
five dialogs. `@radix-ui/react-scroll-area` is added to
`forbiddenBootPackages`, plus a dated `$comment` entry. Against main's
build, the new budget reports all nine guards.
- Limits are unchanged. Boot now measures 402,655 bytes against 429,151,
which is 6.2% headroom. 10% over the new measurement (442,921) would be
a raise, so lowering the limit would leave less than 10%.

Not reached: 10% headroom needs about 12.3 KB more. The remaining boot
code that isn't first-paint UI is small and spread out. The
command-palette placeholder is kept on boot deliberately so Cmd+K opens
instantly. The updates hover-card body is ~2 KB and splitting it would
risk an empty card on an early hover. The plugin collector (5.2 KB) is
how core registers its own Info tab and message time, per the rule that
core uses the plugin API path. Each of these would cost something
visible or break that rule.

## How you verified

Bundle sizes from real builds of main (3678415, same sizes as
f1c5304) and this branch rebased on main (`.br` files, as
`check-bundle-budget.mjs` counts them):

| Closure | main raw / brotli | branch raw / brotli | brotli Δ |
|---|---|---|---|
| boot | 1,717,479 / 428,928 | 1,597,774 / 402,655 | −26,273 (−6.1%) |
| ThreadPage | 1,909,102 / 504,492 | 1,918,632 / 506,727 | +2,235 |
| NewThreadPage | 1,007,979 / 270,590 | 1,025,094 / 274,769 | +4,179 |
| PluginFrontend | 832,313 / 220,554 | 846,772 / 223,750 | +3,196 |
| boot + ThreadPage | 933,420 | 909,382 | −24,038 |
| boot + NewThreadPage | 699,518 | 677,424 | −22,094 |
| boot + PluginFrontend | 649,482 | 626,405 | −23,077 |

Journey growth is the open-target hooks (~3.9 KB) that those pages use,
plus small dialog dependencies.

First content on a real server (measured with the earlier version that
still had the `z` hint, so about 3.6 KB more JS was removed than now):
one `pnpm start:worktree` server with real data (a real agent thread
plus fixtures). Main's and this branch's builds were served by swapping
`index.html` in `apps/app/dist`, so server and data were identical. Each
run used headless Chrome on a fresh navigation with the HTTP cache
cleared and disabled, 4× CPU throttle, 1.6 Mbps / 150 ms RTT. Median of
6 alternating runs; ranges did not overlap for any metric:

| Page | Metric | main | branch | Δ |
|---|---|---|---|---|
| New thread `/` | FCP | 3,594 ms | 3,430 ms | −164 |
| | composer painted | 6,862 ms | 6,731 ms | −131 |
| Thread `/threads/<id>` | FCP | 3,606 ms | 3,432 ms | −174 |
| | timeline painted | 8,942 ms | 8,756 ms | −187 |
| Plugin page `/plugins/automations/automations` | FCP | 3,572 ms |
3,422 ms | −150 |
| | content painted | 7,496 ms | 7,353 ms | −144 |
| | JS downloaded before content (new / thread / plugin) | 745,687 /
979,589 / 732,738 B | 719,291 / 951,279 / 706,155 B | −26.4 / −28.3 /
−26.6 KB |

Manual checks on the branch build:
- Cold load, sidebar and composer: no console errors.
- Updates badge hover card: lists the provider CLI updates.
- Thread page renders its timeline.
- New thread submitted from the composer.
- Thread delete dialog: confirmed, thread deleted.
- Archive on a parent with a child: dialog shows the child count; both
threads archived.
- "New project" path-entry fallback dialog: path submitted, project
created.
- Settings → Updates and the Plugins page render.
- Project rename and delete dialogs opened through the real
`ProjectActionsProvider` in a throwaway test, because their only menu
sits in a header that the current routes don't render.
- A 409 on `GET /threads/<new>/thread-storage/location` right after
submit also happens on main.

Commands:
- `pnpm exec turbo run typecheck lint --filter=@bb/app`
- `pnpm exec turbo run test --filter=@bb/app -- <63 related test
files>`: 63 passed
- `src/vite-journey-chunks.test.ts`: fails before the fix, passes after
- `node scripts/check-bundle-budget.mjs`: OK
- `oxfmt --check`
- Rebased on main (includes #7736); `pnpm exec turbo run build typecheck
lint --filter=@bb/app` and `check-bundle-budget.mjs` pass, and the 40
app test files that touch the changed providers, dialogs, layout and
hooks pass on the merge.
- The built sonner and cmdk code again contains the swipe setter and
sort calls that the `z` hint had removed.

> AGENT GENERATED

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 18, 2026
…y switches (#7731)

## Human comments

## What was wrong

AGENTS.md says a plugin API that performs a core action must be the path
core uses, proven by one contract test table run against every surface.
Only part of that was enforced. The view-level panel table
(`test/panel-controller-contract.tsx`) covered panel tabs, not
`openTerminal`, `openFilePreview` or `openUrl`. The terminal and file
tables were hook-level and mocked `reveal`. There was no table for
ThreadScreen consumers, Markdown surfaces or single-pane layout. So
per-surface switches that turn a feature off for plugin surfaces kept
shipping. Each was a small, reasonable-looking exception that no table
asserted against:

- **#7065.** Plugin thread actions got `experimental_panel` routed to
the focused surface, but their `navigate` came from the app-level
context in `ThreadActionsProvider`, outside every view's navigation
host. From a header thread action, `experimental_openTerminal`,
`experimental_openFilePreview` and `openUrl` returned `false` and did
nothing. The issue's suspected cause (`reveal: openCompactDrawer`) is
not it: that is the same function as `openDrawer`, and terminal
selection already writes `isOpen: true`. That is also why SlopCop's
in-view test did not reproduce it.
- **#2967.** `PluginThreadChat` passed `includePluginMessageActions:
false`, so slot-registered message actions never showed in an embedded
ThreadChat.
- **#7277.** `SplitThreadArea` kept a single pane mounted across the
compact breakpoint only for the `thread` and `new-thread` kinds. A
plugin page swapped between `StandalonePaneContent` and
`WorkspacePaneContent` and lost its DOM and React state.
- **#5340.** `PluginNewThreadComposer` started an unseeded composer on
`null` (the personal project) instead of the remembered New thread
project.

### Earlier issues and fixes from the same root cause

This is the 20th fix in the class. Each earlier one patched a single
surface:

- **Fix PRs:** #1469, #1518, #2026, #3147, #3752, #3867, #3968, #4331,
#4693, #4954, #5128, #6104, #6269, #6291, #6387, #6752, #6754, #6756,
#6763 and #7060.
- **Closed issues:** #1836, #2288, #3395, #4323, #4438, #4480, #4501,
#4951, #6071, #6268, #6289 and #7015.

The open issues the tables catch today are #7065, #2967, #7277 and
#5340. #6311 is covered by the Markdown table, which already passes
because #6405 removed the closure chain.

## What changed

**Guards (written first; each failed on main for the past case named):**

- **Panel table.** `test/panel-controller-contract.tsx` gains three
rows: open a terminal, open a file preview (reusing the tab for the same
file), and open a URL in the in-app browser. Each row must select the
tab and reveal a closed panel. The table runs on the thread view, thread
header row, **thread header action** (new row), New thread screen and
plugin page. On main the header-action row failed all three (#7065).
- **ThreadScreen table.** New `ThreadScreen.surface-contract.test.tsx`
runs against the thread page and plugin ThreadChat full, compact and
timeline. It uses real timeline rows. Every row must show
slot-registered message actions, and every composer must receive the
thread's context-window usage. On main the three ThreadChat rows failed
(#2967). Context usage already passed on every row, so that half of
#2967 was fixed by #6387.
- **Markdown table.** New `markdown-surface-contract.test.tsx` runs
against assistant messages, plugin `Markdown` and plugin document
`Markdown`. It checks thread-token mentions, web-link routing through
the surface's navigation host, and `<video>` identity when the
navigation host changes. It passes on main and guards #6311 and #6756.
- **Single-pane table** in `SplitThreadArea.test.tsx`. Thread, New
thread and plugin page panes must keep their DOM nodes and unsaved state
across four breakpoint crossings. On main the plugin page row failed
(#7277).
- **#5340 test** in `PluginNewThreadComposer.test.tsx`. An unseeded
composer must start on, and submit, the project the user picked in bb's
New thread view. It failed on main.

**One owner, copies deleted:**

- `lib/app-navigation-host.tsx` gains `AppNavigationSurfaceProvider`.
Each surface now registers its *resolved* navigation host while it has
focus: the thread view, New thread, plugin page and Plugins.
`getFocusedAppPanelController` is derived from that registry. The
panel-only `focusedControllers` registry and the `isFocused` argument to
`useAppPanelController` are deleted.
- `ThreadActionCollectors` wraps collectors in
`FocusedAppNavigationSurfaceProvider`. Thread actions' `navigate.open*`
now reaches the same focused surface as their `experimental_panel`. When
no surface has focus, it falls back to the app-level host.
- `includePluginMessageActions` is deleted end to end:
`ThreadScreenTimelineHost`, `ThreadTimelineSurface`,
`ThreadTimelineRows`, `PluginThreadChat` and `ThreadDetailView`.
- `keepsSinglePane` is deleted from `SplitThreadArea`: any single pane
stays in `WorkspacePaneContent`.
- The duplicate `PLUGIN_MARKDOWN_THREAD_MENTIONS` and
`ASSISTANT_THREAD_MENTIONS` constants are merged into one
`AUTHORED_MARKDOWN_THREAD_MENTIONS` exported from
`markdown-preview.tsx`.

**Follow-up from the independent review: missing host fields and
untested panel contexts.**

- **Required host fields.** Every `ThreadScreenTimelineHost` and
`ThreadScreenComposerHost` field is now required (`ThreadScreen.tsx`),
so each surface must state each handler or an explicit `null`. A host
field a surface leaves out now fails typecheck.
- **Shared title actions and environment rules.** New
`thread-screen-hosts.ts` owns the timeline title-action resolver and the
thread environment rules (context environment, reusable environment).
ThreadDetailView and plugin ThreadChat both use it.
- **What plugin ThreadChat newly gets, matching the thread page:**
- Clicking a tool title opens the diff or file, a local file, or a side
chat. On main, `onTitleAction` was missing, so these clicks did nothing.
- The context row above the composer still receives no environment
(`contextEnvironmentId: null`), as on main, so a side chat does not
repeat its parent thread's changed-files row. An opt-in prop for it was
dropped because no plugin used it.
  - "New thread in this environment" is available.
- The unread divider is shown. It now uses the same
`useThreadUnreadDividerState` as the page, and read tracking waits for
the divider, as on the page.
- **ThreadScreen table.** The page row now mounts the real
`ThreadDetailView`, not a hand-built `ThreadScreen`. Two rows were
added: opening a changed file from its timeline title, and the composer
receiving the new-thread action and each surface's expected context
environment (the thread's on the page, none in embedded chats). On
main's `PluginThreadChat`, these fail 5 of 11 rows.
- **Panel table.** New rows for **thread message actions**, **command
palette commands** and **thread new-tab plugin actions**, alongside the
existing surface rows. `CommandPalette` now builds plugin commands
through one `buildFocusedSurfacePaletteActions`, which the table also
uses. The table gains `actionTabs` and `navigation` support flags,
because those three contexts receive only a panel. The **Plugins view**
gets a test that its panel declines every plugin tab without changing
its tabs.
- **Panel tab renderers.** `ThreadTerminalPanel`'s `onOpenLink` and
`onSelectionAddToChat` are required, so each of the three panel tab
renderers must state them. The plugin page's terminal had no
`onOpenLink`; its links now route through that page's in-app browser, as
on the thread and New thread surfaces. I did not merge the three
renderers into one. Their file-preview cases depend on different surface
scopes, and the shared parts are now enforced by types.

**SDK (backward compatible):**

- The JSDoc for `PluginMessageActionRegistration` and
`ThreadChatMessageAction` no longer says embedded ThreadChat hides slot
actions.
- `ComposerCustomization.actions` documents where actions render: the
expanded composer, not the collapsed single-line one.
- `defaultProjectId` documents the remembered-project default.
- New optional `PluginMessageActionRegistration.experimental_surfaces`
(type `ExperimentalMessageActionSurface`): `"thread-view"` is bb's
thread view and `"embedded-chat"` an embedded `ThreadChat`, matching the
SDK docs' wording (`"thread"` alone already means any thread composer in
the composer host's `surface`). Omitted, an action shows on both. The
collector fills that default and rejects an empty or unknown list. It
has an entry in `docs/api_to_audit.md`, on the Plugin Guide's message
actions card (whose stale "main timeline only" bullet is replaced) and
in the bb-plugin-authoring skill, which no longer says embedded
ThreadChat hides slot actions.
- `@get-bb/plugin-sdk` is set to 0.6.161, above main's 0.6.160.
- No wire changes and no CLI changes.

**Message action surfaces (review follow-up):**

- With decision 2, Side chat's own "Reply in side chat" also showed
inside a side chat and in other plugins' embedded chats. Its side chat
tab only exists in the thread view's panel, so on a plugin page it would
create a side chat thread and then fail to open it.
- Each `ThreadScreen` host now states `messageActionSurface`
(`ThreadDetailView` `"thread-view"`, `PluginThreadChat`
`"embedded-chat"`). The timeline reads slots through one hook,
`useSurfaceMessageActionSlots` (`lib/message-action-surface.tsx`), so
every surface filters the same way. This is a filter the registration
owns, not a per-surface switch.
- Side chat registers `experimental_surfaces: ["thread-view"]`. Every
other message action keeps showing in embedded ThreadChat.
- The ThreadScreen table gains a row: an action limited to one surface
shows only there, on all four surfaces. An SDK collector test covers the
default and the validation.

**Not deleted:** `PluginNewThreadComposer`'s
`selectionScope="component-local"`. That switch decides whether SDK
seeds (`defaultProviderId`, `defaultModel`, `defaultEnvironment`, …)
beat core's remembered picks. Switching to the `"new-thread"` scope
would override third-party plugins' seeds and write plugin picks into
core's New thread preferences, and an existing test pins that
separation. This PR fixes only the #5340 project fallback. The
seeded-but-unknown project id case resolves to personal exactly as a
stale remembered id does in core's New thread view, so it is parity and
left unchanged.

## Decisions for review

1. **Thread actions route open\* to the focused pane.** This applies to
header actions and to thread actions run from menus for other threads (a
sidebar row's menu, the New thread screen's recents on a phone, or a
plugin's `experimental_ThreadActionsMenu`). It matches how
`experimental_panel` was already routed. Run from thread A's menu while
thread B has focus:
- `experimental_openTerminal` with A's terminal returns `false`, because
B's panel accepts only B's terminals (`acceptsThreadTerminal`).
- `experimental_openFilePreview` and `openUrl` open in B's panel. A file
preview is addressed by environment and path, not by thread.
- On main, all three returned `false` from every thread action, the
header included. Opening A first and then the tab in A's panel would
need a new "open a thread with a panel tab" path (see decision 7).
2. **Embedded ThreadChat shows every slot-registered message action**,
including compact side chats. Actions that need a thread-context tab
receive the embedding page's panel. That returns `false` where the tab
does not exist, as #2967 asks.
3. **The collapsed single-line composer still leaves plugin actions
out**, as on main. It leaves out bb's own `+` menu and model picker too;
all of them show once the composer expands. An earlier version of this
PR showed plugin actions in the collapsed composer for #3358, but even
with a scrolling strip it crowded the one-line composer on phones, so
that change was reverted and #3358 stays open.
4. **An unseeded plugin NewThreadComposer starts on the remembered New
thread project.** It reads that project but never writes it.
5. **A single plugin page or Plugins pane is no longer remounted at the
compact breakpoint.** On compact it renders through the workspace pane,
with the same close button as before.
6. **"Reply in side chat" stays out of embedded ThreadChat, including
side chats.** Side chat limits its action to bb's thread view with
`experimental_surfaces: ["thread-view"]`. Embedded ThreadChat cannot
open its side chat tab, and a side chat inside a side chat is not
wanted. Other plugins' message actions still show in embedded
ThreadChat.
7. **A side-chat title on a surface whose panel can't host the side chat
opens the side chat thread itself.** Opening the source thread with the
side chat tab would need a new "open a thread with a panel tab" path;
this uses the existing thread navigation instead.
8. **Plugin ThreadChat's thread-info button is left off
(`onOpenThreadInfo: null`).** Thread info is a fixed tab in the thread
page's side panel. From a plugin page, the button would open nothing, so
it is left off.
9. **The standalone plugin model picker keeps
`commandShortcutsEnabled={false}`.** ⇧⌘M toggles the focused composer's
picker, and every composer, plugin composers included, gets it through
`ExecutionControls`. A form-control picker that also grabbed ⇧⌘M would
make the shortcut ambiguous.
10. **The plugin page's new tab keeps `showFileSearch={false}` and a
no-op `onSelect`.** A plugin page has no project, environment or thread,
so there is nothing to search and no recents to select; `onSelect`
cannot fire.
11. **The Plugins view's panel accepts no plugin tabs.** It has no
plugin tab destinations, so a plugin command run there gets a panel that
declines every tab. The new test pins this.
12. **Embedded ThreadChat now shows the unread divider and marks the
thread read once the divider is ready**, the same order as the thread
page. Before, it marked read immediately and showed no divider.

## How you verified

### Live verification (isolated source dev instance, verify-bb)

These ran on the source dev web app at this branch, before the rebase,
with a fresh data directory and the connected local host. A probe plugin
registered three header thread actions (open a terminal, a file and a
URL), a slot message action, three composer actions, and a page holding
ThreadChat full and compact plus an unseeded
`experimental_NewThreadComposer`. A Claude Code Haiku thread produced
the assistant messages. Screenshots and measurements are kept locally.

1. **Header thread actions.** Pass in the web client; the in-app browser
case was not run.
- 1400×900 with the right panel closed: "Probe open terminal" returned
`true`, the panel opened, and a zsh terminal tab was selected.
- With the panel closed again, "Probe open file" returned `true`, the
panel opened, and the README.md preview was selected.
- "Probe open URL" returned `true` and opened
`https://example.com/probe` externally. The web client has no in-app
browser, so the Electron in-app browser path was not run live; the
contract table covers it.
2. **Plugin message actions in embedded ThreadChat.** Pass.
- On the probe page, both ThreadChat full and compact show "Probe
message action" on the user and assistant messages.
- In a real side chat (compact ThreadChat, opened with "Reply in side
chat"), after one reply the assistant message shows "Probe message
action" next to "Send to main thread". After the surfaces follow-up, a
rerun on the rebased branch shows 0 "Reply in side chat" inside the side
chat; the thread page still shows it on both messages. See decision 6.
3. **Plugin actions on a phone (375×812, touch).** The collapsed
composer shows no plugin actions, as on main. After tapping it, the
expanded composer shows all three probe actions before the mic.
4. **Remembered project in an unseeded plugin composer.** Pass.
- After picking Fixture in bb's New thread view, the plugin composer
showed "Project: Fixture", and it still did after a reload.
- After picking No project in New thread, the plugin composer showed
"Project: No project".
5. **Single plugin page across the compact breakpoint.** Pass.
- I typed into the page's input and selected characters 2–6, then
resized 1024 → 767 → 768 → 700 → 1024.
- Throughout, the same input and page nodes stayed, with the same mount
id, the value "unsaved plugin form", focus, and the selection `[2,6]`.
The compact page shows the close button.

### Live verification of the review follow-up (second run, isolated dev
instance and desktop app)

The second run used a fresh dev instance from this branch (`ae6db4b0d34`
plus the side-chat fix below). The URL check also used the source
desktop app (Electron) attached to the same instance and driven over
CDP. Each check compares plugin ThreadChat on the probe plugin's page
with the thread page. The fixtures were Claude Code Haiku threads:
- an "Edits" thread that changed a workspace file (`README.md`) and a
file outside the workspace (`/tmp/.../outside-note.txt`);
- a side chat whose reply was sent back to the main thread;
- two threads that were marked read and then got an unread reply.

1. **Tool title opening a changed workspace file.** Match.
- On the thread page, clicking `README.md` opened a README.md preview
tab in the thread's panel.
- In plugin ThreadChat, it opened the same preview in the plugin page's
panel.
- On both, the git Diff tab declines this file target, so both fall back
to the file preview.
2. **Tool title opening a file outside the workspace.** Match.
`outside-note.txt` opened a host-file preview in each surface's own
panel.
3. **Side-chat title ("Message from side chat").** Mismatch found and
fixed.
- On the thread page, clicking it opened the side chat in the thread's
panel.
- In plugin ThreadChat, it did nothing: the plugin page's panel has no
thread side-chat tab.
- Fix: the shared resolver now opens the side chat thread itself when
the surface's panel declines the tab. After the fix, plugin ThreadChat
navigates to the side chat thread; the thread page is unchanged and
still opens it in its panel. Covered by `thread-screen-hosts.test.tsx`.
- Related finding, already on `main` and not caused by this PR: both
surfaces label the row "Message from Agent", with no link, until the
hidden side-chat thread is in the query cache. Sender metadata is read
only from cached threads. After a reload with the side chat tab closed,
the thread page shows the same unlinked label. Not changed here.
4. **"New thread in this environment".** Match.
- The thread page opened New thread with project Fixture and "Reuse"
selected.
   - Plugin ThreadChat, about 920 px wide, did the same.
- In a probe column about 250 px wide, the composer's environment row is
clipped. This comes from the narrow container; the side chat tab at
about 520 px shows the row.
5. **Unread divider.**
- Thread page (thread C): the "NEW" divider sits above the unread second
reply.
- Plugin ThreadChat full and compact (thread B): the divider sits in the
same place.
- On both, the thread stayed unread until there was user activity (mouse
and keyboard input), then `lastReadAt` advanced and the divider stayed
on screen. Read timing matches.
6. **Plugin-page terminal link (desktop app).** Match.
- On the plugin page, ⌘-clicking `https://example.com/terminal-link` in
a panel terminal opened an in-app browser tab ("Example Domain") in the
plugin page's panel. On main this link had no handler on the plugin
page.
- On the thread page, the same click opened the same in-app browser tab
in the thread's panel.

### Tests and checks

- After rebasing onto main (`28cdd915db4`) and dropping
`experimental_environmentContext`: `typecheck lint` pass for `@bb/app`,
`@get-bb/plugin-sdk`, side chat and plugin-api-docs; the 15 changed app
test files pass (533 tests, 16 skipped); plugin SDK (439), side chat
(27) and plugin-api-docs (75) tests pass; the plugin SDK version check
passes. A live rerun on the rebased build showed "Probe message action"
in both the thread page and embedded ThreadChat, with "Reply in side
chat" only on the thread page.


- Each guard was run against main's version of the changed component and
failed as described above. All guards pass with the fix.
- A targeted run of the 35 affected test files passed after the review
follow-up: 1,112 tests, with 16 skipped.

- `pnpm exec turbo run typecheck lint --filter=@bb/app`: pass. The
composer plugin lint shows 4 warnings, all of which were already there.
- `node apps/app/scripts/check-bundle-budget.mjs` after the rebase: the
boot payload is 418.6 KB brotli against a 419.1 KB budget.
- The first CI run's other failures were 15 s timeouts in `@bb/logger`
(Windows) and `@bb/db` resolved-item pruning. This PR touches neither
package.
- Not run on a native iOS or Android device, and not in the Electron
in-app browser.
- After rebasing on main and adding message action surfaces: the 15
affected app test files pass (651 tests, 16 skipped);
`@get-bb/plugin-sdk` typecheck, lint and tests pass (39 files);
side-chat and plugin-api-docs tests pass; `typecheck lint` pass for
`@bb/app` and both plugins; the boot bundle budget passes.

Fixes #7065
Part of #2967. Gaps 1 and 2 are covered; gap 3, the per-chat identity
seam for content scripts, is not in this PR.
Fixes #7277
Part of #5340. The unseeded-project half is fixed; the unknown-seed half
is kept as parity, as explained above.

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

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment