Skip to content

Seed toCompose and NewThreadComposer drafts with mention parts - #8050

Merged
ymichael merged 2 commits into
mainfrom
bb/8014-tocompose-newthreadcomposer-seed-the-draft-thr_y5dbemr88r
Nov 23, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/8014-tocompose-newthreadcomposer-seed-the-draft-thr_y5dbemr88r

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

toCompose({ initialPrompt }) and NewThreadComposer's initialPrompt only took a string. The seed path recognized only serialized @thread:, @project: and @section: tokens. Path, attachment and plugin mentions have no serialized form, so a hand-off could only add them as plain text. A mounted composer's useComposer().insert() already accepted ComposerInsertPart[]; the hand-off path had no equivalent. Core had the same gap: its "Edit the bb plugin/skill … at " hand-offs put the path into the prompt as text.

What changed

  • SDK contract (app-contract.ts): NewThreadComposerProps.initialPrompt and BbNavigate.toCompose's initialPrompt are now string | readonly ComposerInsertPart[]. The empty-draft-only seed semantics are unchanged, and the JSDoc now describes the parts form. SDK bumped to 0.6.184.
  • One conversion path (internal/composer-handle.ts): insert()'s private insertValue is now the exported composerDraftFromInsertParts(parts, { pluginId, mentionText }). insert() and both seed surfaces call it. A part without kind resolves to the calling plugin. If there is no plugin (core, pluginId: null), it throws.
  • App plumbing:
    • initialPromptSeedFromComposer (lib/plugin-composer-handle.ts) turns a string or parts into an InitialPromptSeed, which is either a string or { text, mentions: PromptTextMention[] }.
    • toCompose converts before it navigates, so an invalid provider throws to the caller the same way insert() does. PluginNewThreadComposer converts with its plugin id.
    • RootComposeView reads location.state.initialPrompt with a zod schema (initialPromptSeedSchema, built on promptTextMentionSchema) and memoizes the result on location.state.
    • useInitialPromptDraft takes either form. Structured seeds skip serialized-token parsing and thread-title resolution, so mentions are recreated exactly as insert() would. They still go through the same query so the draft stays structurally stable across re-renders.
  • Core hand-offs (shared-ui/resource-edit-prompt.ts, ToolsView, SkillsLibrary): buildPluginEditThreadPrompt / buildSkillEditThreadPrompt now return ComposerInsertPart[] with a path mention (a directory for plugins, a file for skills, labelled with the basename). The callers pass these through initialPromptSeedFromComposer, the same path plugins use. The sent prompt text now reads … at @/path/to/plugin/. I want to , which is what the user would get by picking the path from @.
  • Testing harness: TestNewThreadComposer renders a parts seed's text.
  • Docs: the bb-plugin-authoring references for NewThreadComposer and toCompose describe the parts form.

No server/daemon wire change.

How you verified

  • pnpm exec turbo run typecheck --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=@bb/shared-ui passes.
  • pnpm exec turbo run lint passes for the same packages.
  • Targeted vitest runs all passed: resource-edit-prompt, RootComposeView, initial-prompt-draft, PluginNewThreadComposer, plugin-composer-handle, SkillsView and plugin-slot-mounts in apps/app, plus the plugin-sdk app-harness test.
  • New tests:
    • PluginNewThreadComposer.test.tsx: core's plugin-edit hand-off goes through RootComposeView location state and seeds the root draft with a path mention at the right range. A plugin's [text, { provider, id, label }] seed submits a plugin mention resolved to that plugin (itemId: "notes:…").
    • resource-edit-prompt.test.ts: plugin and skill hand-offs produce the expected text and path-mention ranges. A part without kind throws when core seeds the draft.
    • RootComposeView.test.ts: a structured location-state seed parses, and one with a malformed mention is rejected.

Fixes #8014

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 23, 2026 12:44
toCompose({ initialPrompt }) and NewThreadComposer's initialPrompt now
accept ComposerInsertPart[] as well as a string. Parts convert through
composerDraftFromInsertParts, the same function useComposer().insert()
uses, so path, attachment and the plugin's own mentions arrive as pills.

Core's plugin and skill "Edit ... at <path>" hand-offs now seed the path
as a path mention pill through the same conversion and location state.

Fixes #8014

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…slot

The Edit plugin/skill prompts and the @/path token reader now build path
mentions through one client-core pathMentionResource helper, next to the
serializer it inverts. The prompt builders move from shared-ui into
apps/app/src/lib, where their only callers and test already live.

NewThreadComposer no longer throws during render for parts insert()
would reject: it logs a [plugin:<id>] warning and opens with an empty
draft, as its other props fall back on bad input. toCompose and insert()
still throw to the caller, and now also reject an empty item id, which
the server would otherwise refuse only at send time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/8014-tocompose-newthreadcomposer-seed-the-draft-thr_y5dbemr88r branch from 3e95651 to e102385 Compare November 23, 2026 20:45
@ymichael
ymichael merged commit 420c553 into main Nov 23, 2026
52 checks passed
@ymichael
ymichael deleted the bb/8014-tocompose-newthreadcomposer-seed-the-draft-thr_y5dbemr88r branch November 23, 2026 20:55
ymichael added a commit that referenced this pull request Dec 1, 2026
…8507)

## Human comments

## What was wrong

Boot JavaScript grew from 393.2 KB to 418.9 KB brotli between #7744 (Nov
18) and main, leaving 0.2 KB under the 419.1 KB limit. Two of the
largest steps were static edges from the boot path into page-only code:

- #8089: `plugin-navigation-hooks` imports `useTimelinePaneThreadId`
from `timeline-viewport.tsx`, which also defined
`TimelineViewportScrollSource`. That put `bottom-anchored-scroll-body`
and `scroll-position-keeper` on boot.
- #7960: `active-composer.ts` built the active composer's plugin handle
itself, so the action-context binder (on boot) pulled in
`plugin-composer-handle`, the SDK's `composer-handle` and
`composer-draft-actions`, `plugin-composer-host` and
`composer-editor-registry`. #8050 added a second path to the same
modules: plugin navigation converts `initialPrompt` parts through
`plugin-composer-handle.ts`.

#7962's boot growth (~1 KB brotli) is the exclusive-pick logic the
sidebar thread list and navigation need before they paint, so it stays.

## What changed

- `TimelineViewportScrollSource` moved to
`apps/app/src/lib/timeline-viewport-scroll-source.tsx`;
`timeline-viewport.tsx` exports `useTimelineViewportStore` for it.
- `ActiveComposerCandidate` gained `handle(pluginId)`. `composer-root`
registers a factory built by the new `active-composer-handle.ts`, and
`getActiveComposerHandle` calls it, so `active-composer.ts` no longer
imports the handle code. `experimental_useActiveComposer` uses the same
builder.
- `initialPromptSeedFromComposer` and `mentionText` moved to
`apps/app/src/lib/initial-prompt-seed.ts`. It imports
`composerDraftFromInsertParts` from a new SDK internal subpath,
`@get-bb/plugin-sdk/internal/composer-draft-transforms`, where that
function now lives. A re-export through `internal/composer-handle` still
kept the whole module on boot.
- Plugin SDK 0.6.216 for the new subpath.
- `bundle-budget.json`: `splitBoundaries` boot guards for
`bottom-anchored-scroll-body.tsx`, `active-composer-handle.ts` and
`plugin-composer-handle.ts`, plus a dated `$comment` entry. Limits
unchanged.

## How you verified

Real builds of main (e0c49e2) and this branch, brotli bytes from the
`.br` files `check-bundle-budget.mjs` counts:

| Closure | main | branch | Δ |
|---|---|---|---|
| boot | 428,920 | 419,163 | −9,757 |
| ThreadPage | 498,511 | 507,873 | +9,362 |
| NewThreadPage | 268,226 | 277,858 | +9,632 |
| PluginFrontend | 219,813 | 229,475 | +9,662 |
| boot + each page | | | −95 to −395 |

Raw boot: 1,708,056 → 1,668,548. Every page shell uses the scroll body
(`page-shell.tsx`) and every page loads the plugin runtime that needs
the composer handle, so the code moved into the shared page chunks. The
shell's critical path shrinks, the total before page content is
unchanged, and boot is back to 2.3% headroom. I didn't measure paint
timings.

- Negative control: re-adding the `timeline-viewport` → scroll-body
import and a `plugin-navigation-hooks` → `plugin-composer-handle` import
fails the check with both new guards, and boot returns to 418.6 KB.
- `pnpm exec turbo run test --filter=@bb/app
--filter=@get-bb/plugin-sdk`: 709 + 47 test files pass.
- `pnpm exec turbo run typecheck lint --filter=@bb/app
--filter=@get-bb/plugin-sdk`, `node
apps/app/scripts/check-bundle-budget.mjs`, `oxfmt --check`.
- Live `pnpm start:worktree` with a real Claude Code thread, driven in
headless Chrome: no console errors, scroll-to-latest works, the outline
rail's active tick follows scrolling, and typing in the composer works.

> AGENT GENERATED

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toCompose / NewThreadComposer: seed the draft with mention parts, not only serialized thread/project/section tokens

1 participant