Skip to content

Test and document warm environments with extra folders for any provider - #8094

Merged
ymichael merged 2 commits into
mainfrom
bb/warm-env-folders-thr_psx98pzvux
Nov 24, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/warm-env-folders-thr_psx98pzvux

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

#7869 lets a plugin hold environments (hold: "plugin") and hand one to a new thread with ctx.adopt. Nothing showed that the folders a provider records with an environment (additionalPaths) survive that hand-off, or a later restore. The Plugin Guide did not explain how a custom provider keeps its own prebuilt environments.

What changed

No core change: the engine already handles these cases. This PR adds the tests that prove it, and the docs.

Tests (apps/server/test/environments/environment-holds.test.ts). The test provider now has a restore and can return additionalPaths. New cases:

  • A held environment keeps the folders it was created with when a thread's create adopts it and omits additionalPaths. The environment response shows them.
  • A create that returns additionalPaths after adopt replaces them.
  • A restore of an adopted environment receives its folders in previous.environment.additionalPaths, and the rebuilt environment records the folders restore returns.
  • A restore that adopts another held environment keeps that environment's folders.

Docs.

  • bb-plugin-authoring/references/backend-machines.md: a new section, "Keeping prebuilt environments for your provider". It shows a complete provider whose environments are an app checkout plus sibling api and docs checkouts. It covers building held environments with experimental_create({ hold: "plugin" }), telling them apart in create by heldBy, adopting a ready one, refilling, returning the resource after adopt (or remove() gets null), and what restore must return.
  • Plugin Guide (plugin-api-docs/src/surfaces.ts): a reference paragraph on the Environment providers surface with the same rules.

replacedProjectFolders is left to #8065, which has not landed.

How you verified

Live. I ran the docs example as a real plugin (bb plugin install of a local "stack" provider) on a pnpm start:worktree server.

  • bb stack warm <project> <host> built a held environment with app, plus api and docs as additionalPaths.
  • A Claude Code thread on the Stack provider adopted it. The hold cleared, the refill built a new held one, and the agent listed the warm environment's api and docs folders as writable.
  • Archiving the thread and deleting its environment removed the adopted stack's directory, so remove() received the resource.
  • bb thread restore-environment rebuilt it with new api and docs folders, and the agent listed those after the restore.
  • The first run caught two mistakes in my draft example, now fixed:
    • With no resource returned after adopt, the stack's directory was never removed.
    • Returning previous.environment.additionalPaths as-is from restore pointed at the destroyed folders.

Checks:

  • environment-holds.test.ts: 21 passed.
  • pnpm exec turbo run typecheck lint --filter='...[origin/main]'.
  • The bb-plugin-plugin-api-docs, bb-plugin-bb-guide and @bb/templates tests.
  • The docs example typechecks against the plugin SDK.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 23, 2026 17:01
Tests prove that an environment a plugin holds keeps the additionalPaths its
provider returned when a thread adopts it, that create can replace them after
adopt, that restore receives the destroyed environment's folders, and that a
restore which adopts keeps the warm environment's folders. No core change was
needed.

The Plugin Guide and the bb-plugin-authoring machines reference now show how a
custom environment provider keeps prebuilt environments and hands them out,
with a multi-folder provider as the example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The doc-example test wraps each SDK example in a function body, so the example
cannot export a plugin factory or call undeclared helpers. It now registers the
provider from a function that takes the plugin's own StackBuilder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 7e6d281 into main Nov 24, 2026
47 checks passed
@ymichael
ymichael deleted the bb/warm-env-folders-thr_psx98pzvux branch November 24, 2026 06:08
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