Skip to content

Make prompt attachments portable across projects and machines - #4685

Merged
ymichael merged 4 commits into
mainfrom
bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y
Oct 5, 2026
Merged

ymichael merged 4 commits into
mainfrom
bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y

Conversation

@ymichael

@ymichael ymichael commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Prompt history and drafts represented uploaded files with project-relative paths, which become ambiguous when reused in another project. Absolute file paths likewise carried no record of which machine they live on. Adapters used zero for unknown sizes.

What changed

  • Uploaded attachments carry sourceProjectId: uploads and prompt history set it, drafts and previews preserve it, and core validates the source and copies the file into the destination project before accepting a create, send, or queued message, then strips the field before persisting. The destination copy survives deletion of the source project.
  • Absolute file paths carry hostId the same way: prompt history reports the machine of the thread that sent them, drafts preserve it, and core rejects a message whose target thread runs on another machine, then strips the field. Stored and dispatched input is unchanged, so the daemon protocol is unchanged.
  • ComposerAttachment is a union with at most one of the two fields; drafts, snapshots, and replacements share that shape, so returning a snapshot with new text type-checks and keeps every attachment.
  • sizeBytes is optional: absent means unknown. A zero size in a draft is treated as unknown, both when a stored draft is read and when a draft is sent, so plugins that wrote 0 as a placeholder (the field used to be required) keep working instead of failing the daemon's staging size check.
  • Copying an upload across projects keeps its original name and MIME type, so extensionless images stay images.
  • Plugin SDK 0.6.18 → 0.6.19. Both fields are stable, without an experimental_ prefix. Updated the Plugin Guide.
  • Prompt Library/B4 remains outside this PR. Its mapper drops sourceProjectId and needs a follow-up.

This replaces the attachment-ID version of this PR. Identifying uploads by project + path needs no second identity system, so the ID routes, SDK methods, CLI syntax, dual-format history, internal type split, and client-side legacy lookup are gone. The PR goes from +3,185/−804 to +713/−107.

How you verified

Latest rebase onto origin/main (2026-10-05): resolved the SDK version conflict by bumping both version declarations to 0.6.19. Typecheck/lint passed (132/132 Turbo tasks); focused server attachment/history/accounting tests passed (35 tests), and client-core, Plugin SDK, server-contract, and host-daemon-contract suites passed (787 tests).

  • pnpm exec turbo run typecheck lint --filter='...[origin/main]': 131/131 tasks pass, no new lint warnings.
  • pnpm exec turbo run test --filter='...[origin/main]': the contract allowlist failures caused by the new field were fixed; every other failure was in an untouched suite and passed when rerun in isolation.
  • Real-database tests: cross-project restore of history files and images into another project's queued message; history reports hostId, a thread on another machine rejects it, and a thread on the same machine stores the input without the field; host binding accepts a matching machine and rejects a mismatch or a machine on an uploaded path; a cross-project copy keeps the uploaded name and image type.
  • Draft persistence round-trips both fields; a type test checks that one attachment cannot carry both and that a draft snapshot is a valid replacement.
  • No manual UI verification has been performed for this version.

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y branch from 4e88373 to 02d4005 Compare October 2, 2026 17:44
@ymichael ymichael changed the title Make prompt attachments portable across projects Make prompt attachments portable with explicit attachment and host references Oct 2, 2026
@ymichael
ymichael force-pushed the bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y branch 3 times, most recently from f0316db to 43ddbda Compare October 2, 2026 23:37
@ymichael ymichael changed the title Make prompt attachments portable with explicit attachment and host references Make prompt attachments portable across projects and machines Oct 2, 2026
ymichael and others added 4 commits October 5, 2026 11:18
Prompt history now reports the machine of the thread that sent an absolute
file path as experimental_hostId, mirroring experimental_sourceProjectId for
uploads. Drafts preserve it, and core rejects a create, send, or queued
message whose target thread runs on another machine, then strips the field
before persisting, so stored and dispatched input is unchanged.

ComposerAttachment is now a union that carries at most one of the two
fields, and drafts, snapshots, and replacements share that exact shape.
Copying an upload across projects keeps its original name and MIME type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rename experimental_sourceProjectId and experimental_hostId on prompt
inputs, uploads, drafts and ComposerAttachment to sourceProjectId and
hostId, and remove their API audit entry now that they are stable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Plugins had to fill the formerly required ComposerAttachment.sizeBytes and
commonly wrote 0 for an unknown size. Main dropped that 0 when converting a
draft to prompt input; the portable-attachments change forwarded it, so the
daemon's staging size check failed the turn. Drop 0 again: an exact empty
size verifies nothing, and stored drafts already read 0 as unknown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y branch from 29c9d69 to a54e7b7 Compare October 5, 2026 18:20
@ymichael
ymichael merged commit ddef378 into main Oct 5, 2026
60 of 61 checks passed
@ymichael
ymichael deleted the bb/c1-portable-prompt-attachments-with-honest-sizes-thr_9sh9gamm7y branch October 5, 2026 18:44
ymichael added a commit that referenced this pull request Oct 5, 2026
## Human comments

## What was wrong

Reusable prompts had no bundled picker for searching history, previewing
a full prompt, and keeping favorites. B1–B3 provide the paged history
API, popup host, and composer command path; this slice supplies their
Prompt Library consumer.

## What changed

Adds the forkable Prompt Library plugin: **Ctrl+R** or **+ → Prompts…**,
fuzzy search with Thread/Project/All scopes, Markdown preview,
persistent starred text and mentions, and insertion at the retained
caret. Empty drafts restore history text, mentions, and attachment
objects; nonempty drafts receive text and mentions. Insertion never
sends a message.

**Disabled by default.** Enable Prompt Library in Settings → Plugins or
run `bb plugin enable bb--prompt-library` to review it. Includes `bb
prompts search|list|star|unstar`, typed plugin RPC, the plugin skill,
CLI guide/configuration documentation, and bundled marketplace wiring.
Uses B1's `experimental_promptHistory.list`, B2's `experimental_popups`
registrations, and B3's composer command API; no new SDK surface or
daemon wire change.

History attachment fields pass through the mapper and RPC, including
unknown extension fields. The attachment schema follows main's mutually
exclusive project/host ownership contract and accepts unknown sizes.
Starred prompts store text and mentions only. The standalone Vitest
configuration keeps forks independent of monorepo test tooling.

## How you verified

- Rebased onto `origin/main` at
`95750b88485a882bf9ea954c1655797002f60836`; preserved main's diagnostics
documentation when resolving the only conflict.
- Merged `main` at `1904796758` (picks up #4933's workspace bundle
budget, which fixed the `Checks` failure). Main's new public-marketplace
test from #4938 then required off-by-default builtins to be listed, so
`prompt-library` is added to `OFF_BY_DEFAULT_BUNDLED_PLUGINS` in
`apps/web`; the marketplace page now shows `bb plugin enable
bb--prompt-library`. `turbo run test typecheck lint --filter=@bb/web`
passes.
- `pnpm exec turbo run typecheck lint test
--filter=bb-plugin-bb--prompt-library --concurrency=4`: all 9 tasks
passed, including 25 tests. Restore cases cover file/image attachments
with project or host ownership and preservation of unknown extension
fields.
- `env -u BB_CLI -u BB_SERVER_URL -u BB_ACCOUNT_POOL_PARENT_URL pnpm
exec turbo run test --filter=@bb/server --
test/services/plugins/builtin-plugins.test.ts`: all 28 tests passed.
- `node scripts/check-plugin-forks.mjs plugins/prompt-library
--concurrency=1`: independent install, typecheck, tests, and plugin
build passed.
- Earlier UI verification passed in desktop Chromium, 390px
coarse-pointer Chromium, and iPhone 16 / iOS 18.4 Simulator Safari:
preview, Back, insertion without sending, and starring. Rebase changes
are limited to documentation resolution and attachment compatibility.
- SDK generation dependencies remain explicit in Turbo, preserving the
clean-CI fix.
- Product path on the merged head (`pnpm start:worktree`, headless
Chromium → server → daemon → real providers): Ctrl+R in follow-up and
new-thread composers; Thread/Project/All and Project/All scopes with
per-composer persistence across reload; fuzzy search; Cmd+S star/unstar
and Star current draft; insertion at the caret without sending;
empty-composer restore of an image; starred insert dropping attachments.
Attachment ownership from #4685 was sent through real providers: a
project A image restored into a project B new thread was copied
byte-identically and described correctly, and an API-seeded
absolute-path file restored with its `hostId` was read by the provider.
Unknown sizes stay `0`, which the SDK documents as unknown; the file
chip shows no size. Not re-run on this head: compact drawer / iOS
Simulator (earlier pass above), host-mismatch rejection (single
machine).
- Mention round-trip on the same server: workspace-file, cross-project
thread and Agent Annotations plugin mentions keep identical resources
(plugin `itemId` included) through empty, at-caret and starred recall.
Re-sent prompts store the same resources at shifted offsets, and real
providers resolved each target.
- Known core race, not changed here: if Ctrl+R arrives within ~16 ms of
an arrow-key caret move, ProseMirror has not yet synced the selection,
so the prompt is inserted at the previous caret. It was reproduced only
at automation speed and nothing is sent. The fix belongs in core's
composer popup/selection handling.

Reviewer checklist (run CLI commands against the worktree instance):

1. Confirm Prompt Library is initially disabled, then enable it through
Settings → Plugins or `bb plugin enable bb--prompt-library`.
2. Run `bb prompts star 'Review the release notes before merging'
--json`, then `bb prompts search 'rls nts' --json`. Expect one
fuzzy-matched starred prompt with highlighted characters.
3. Open a new-thread composer, press Ctrl+R, and search `rls nts`.
Expect a starred result and full preview. Select Insert: the picker
closes and the draft fills without sending.
4. With an existing draft, reopen the picker and insert a result. Expect
text and mentions at the retained caret, preserving existing content.
Arrow keys move selection, Tab changes scope, and Cmd/Ctrl+S toggles
starring.
5. At a compact touch width or in Simulator Safari, choose **+ →
Prompts…**. Expect the shared bottom drawer. Tap a row to preview it,
use Back to return, then Insert to populate the draft and close. The app
root retains neither `inert` nor `aria-hidden` in the Chromium check.

> 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant