Skip to content

Let an automation choose its environment in the New thread composer - #6056

Closed
alexandre-vl wants to merge 22 commits into
get-bb:mainfrom
alexandre-vl:bb/automation-environment-composer
Closed

alexandre-vl wants to merge 22 commits into
get-bb:mainfrom
alexandre-vl:bb/automation-environment-composer

Conversation

@alexandre-vl

@alexandre-vl alexandre-vl commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

An automation's editor could change only the prompt, model, reasoning and permission mode. Only CLI flags could change where each run worked, and only to a workspace path, a new worktree or an existing environment. The plugin could not store the other choices the New thread composer offers:

  • agentEnvironmentSchema had only reuse, host and project-default. It had no provider environment: no worktree from a named branch, no composition such as berth, no checkout on another machine. Executions had no agent options.
  • The detail view hid part of what was stored: a worktree from dev read "New worktree".
  • bb automation create --new-environment worktree, or a workspace path, ran on the first connected host in the list, not on the invoking thread's machine.

The SDK's experimental_NewThreadComposer is the New thread screen's own component, but it could not hold a saved request:

  • it let the project change;
  • it ignored a project-default seed;
  • it persisted drafts and took attachments;
  • it dropped agent options;
  • it offered plugin send-menu rows such as "Send later…".

Stacked on #6055, which builds on the merged #6054. This branch contains their commits, so review only 9cb4299. eb49add and the merges 45db005, ba0ef55 and c7de022 bring in #6055 and main, and move the SDK version.

What changed

  • Composer (@get-bb/plugin-sdk 0.6.75, after Let a project choose the environment its new threads start in #6055's 0.6.74; the automations plugin requires >=0.6.75): six optional props, mapped onto core's own options. The defaults keep today's behavior for the New thread screen, Settings and the showcase.

    • allowProjectChange sets core's project lock.
    • allowProjectDefaultEnvironment adds a "Project default" entry that names what the default resolves to, and submits {type: "project-default"}.
    • persistDraft={false} keeps the draft in memory.
    • allowAttachments={false} removes attachments.
    • defaultSessionOptions seeds agent options. Returning to an earlier seed now resets edited options.
    • allowPluginCustomizations={false} applies suppressPluginComposerCustomizations, as the sent-message editor does. It hides send-menu rows, banners and commands from plugins.
    • A save from a plugin composer no longer clears the New thread screen's machine pick for that tab.
  • Automation data:

    • a provider environment variant with the same shape threads.spawn takes, and sessionOptions (null clears them). Both are stored as JSON, so there is no migration.
    • Each run passes both to threads.spawn unchanged.
  • Refused on save, because every run would fail (service, options, environment):

    • an agent option that the model on that machine does not list or accept;
    • options on an automation that re-prompts an existing thread;
    • a provider that is not installed;
    • a plain provider without a machine;
    • a composition pinned to another machine.

    Changing the provider, or switching to re-prompting a thread, drops the stored options.

  • Editor UI (detail-view.tsx, composer-request.ts):

    • Edit prompt opens the composer in place, seeded with the stored execution. Saving replaces the whole execution.
    • Thread, project and section mentions are stored as @thread:, @project: and @section: tokens. File and command mentions keep their text.
    • The editor refuses an attachment, a plugin mention, a changed project or an empty prompt with a toast, and keeps the draft.
    • The footer names the environment, for example "Worktree on david · from dev", including a checkout path when one is kept. An unusable environment shows "Environment unavailable: … Runs fail until it is fixed."
    • An automation that re-prompts an existing thread keeps the prompt-only editor.
  • CLI: bb automation create|update gain these flags, which follow bb thread spawn:

    • --environment-provider and --environment-inputs;
    • --machine, which must be persistent;
    • --new-machine and --machine-inputs;
    • --option and --clear-options;
    • --environment project-default.

    show and list print the environment and options. A workspace path or --new-environment now runs on the invoking thread's machine, or the server's.

  • Docs:

    • the automations skill and its references: the differences from bb thread spawn, the option check, and when options are dropped;
    • PLUGIN_OVERVIEW.md and the composer's TSDoc;
    • docs/api_to_audit.md: its consumer, each prop, a corrected item 4, and why the New thread screen has no Project default entry;
    • frontend-components.md and the Plugin Guide surface.
  • No server/daemon wire change, so no HOST_DAEMON_PROTOCOL_VERSION bump.

Known limits

  • A composition such as berth starts a new machine for every run, because core makes a thread's machine from an ephemeral provider ephemeral (provider-orchestration.ts). Nothing in the checkout carries over from one run to the next.
  • Not run live with berth, because it is not installed in the dev instance. Its label, run request and machine rule are unit-tested.
  • On a new machine, agent options are checked against the primary host's model catalog: providerRoutingForEnvironment has no machine to ask yet. The check is skipped when the catalog fails to load or lacks the model.
  • Plugin rows in the plus menu still appear in the editor, as they do in the sent-message editor (Make composer selection reactive and move Automation/Plugin rows into plugins #4502).

How you verified

  • New tests:
    • Composer, in PluginNewThreadComposer.test.tsx:

      • project lock;
      • project-default round trip and routing;
      • in-memory drafts and attachments;
      • agent options and their A→B→A re-seed;
      • the tab's machine pick;
      • plugin customizations.

      Also in new-thread-environment-seed, EnvironmentPicker, NewThreadPromptBox, PromptBoxInternal.test.tsx (suppressed send-menu rows, rendered through ComposerBox since Ship bb's composer as the bundled Composer plugin #6122 moved PromptBoxInternal into plugins/composer) and PluginComposerBanners (suppressed plugin banners).

    • Automations:

      • agent-environment.test.ts: the run request, permission routing, option checks and drops, environment refusals;
      • composer-request.test.ts, automation-environment.test.ts and the editor in detail-view.test.tsx;
      • the CLI and the RPC update in server-harness.test.ts, including a temporary machine and options the model lacks.
  • Mutation checks: breaking the code by hand made the new tests fail:
    • 14 breaks in the composer;
    • the CLI's machine check and thread rule;
    • both wirings of allowPluginCustomizations;
    • the service's option rules;
    • the re-seed and machine-pick fixes.
  • pnpm exec turbo run typecheck lint test --continue --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=bb-plugin-plugin-api-docs --filter=bb-plugin-bb-guide --filter=bb-plugin-automations --filter=@bb/domain --filter=@bb/templates --filter=@bb/cli:
    • typecheck and lint passed with 0 errors;
    • tests passed: @bb/app 6277, @bb/cli 900, @get-bb/plugin-sdk 389, @bb/domain 258, bb-plugin-automations 225, bb-plugin-plugin-api-docs 74, @bb/templates 46, bb-plugin-bb-guide 7;
    • @bb/app comes from a rerun after the last fix. In the full run before it, ThreadActionsMenu.test.tsx "coalesces rows that mount a moment apart into one change" failed under load; it passes alone and in the rerun.
  • Reviews: two independent reviews found 0 high, 3 medium and 13 low issues. Each is fixed here, or documented where the answer is a policy: the New thread screen's entry, and a locked composer's fallback to the personal project.
  • SDK version: at 0.6.75, after merging Let a project choose the environment its new threads start in #6055 and main:
    • check-npm-version-guard.mjs printed npm version guard: PASS — @get-bb/[email protected] is not on npm yet. The publish job will ship this version.
    • .github/workflows/check-plugin-sdk-version.mjs printed Plugin SDK surface changed in 1 file(s) with a version bump.
    • typecheck lint over the 14 packages this branch touches, Let a project choose the environment its new threads start in #6055's included, passed (25 tasks).
    • Tests passed: @bb/app 6361, @bb/server 3694, @bb/cli 898, @bb/db 633, bb-plugin-tasks 410, @get-bb/plugin-sdk 398, @bb/domain 259, bb-plugin-automations 232, @bb/sdk 123, @bb/server-contract 78, bb-plugin-plugin-api-docs 75, @bb/templates 46, @bb/demo-server 15, bb-plugin-bb-guide 7.
    • One @bb/server test failed on my machine: bb-official-generator.test.ts expects git log --format=%cI to print 2026-01-02T03:04:05Z, and git 2.43 prints 2026-01-02T03:04:05+00:00. This PR does not touch that test or its script.
  • Live, on 9cb4299: a fresh pnpm dev with one machine (david), project "Shop" whose default is Worktree on david, headless Chrome.
    • Edit prompt → Environment → Worktree → Branch from: dev → Save:

      • the footer read "Worktree on david · from dev";
      • bb automation show --json stored {"type":"provider","environmentProviderId":"git-worktree","machine":{"type":"existing","hostId":"host_…"},"inputs":{"branch":{"kind":"named","name":"dev"}}};
      • reopening the editor restored Worktree and Branch from: dev.
    • An automation created with --new-environment worktree --base-branch dev read "Worktree on david · from dev". On main it read "New worktree".

    • With the environment-git-worktree plugin disabled, the saved automation showed "Environment unavailable: the git-worktree environment provider is not installed. Runs fail until it is fixed."

    • The CLI printed:

      $ bb automation show <id> --project <project>
        Environment: Worktree on david · from dev
      $ bb automation update <id> --project <project> --option nope=1
      Opus 5.5 takes no agent options, so nope cannot be set.
      $ bb automation update <id> --project <project> --environment-provider nope --machine david
      Unknown environment provider 'nope'. Available: project-checkout, git-worktree.
      $ bb automation update <id> --project <project> --environment-provider git-worktree --environment-inputs '{"branch":{"kind":"named","name":"dev"}}' --base-branch dev
      --base-branch requires --new-environment worktree; an --environment-provider takes its branch through --environment-inputs.
      
    • In an earlier live run, before the review fixes, choosing Project default stored {"type":"project-default"}. Until allowPluginCustomizations existed, the editor offered "Save draft…" and "Send later…"; the After editor below shows a single send button.

Before / after

Before: #6055's head 44e31b5. The Worktree label row is from main at b143a2286; #6055 renders it the same, "New worktree". After: 9cb4299. Same setup as #6055: fresh pnpm dev, project "Shop", one machine david, headless Chrome at 1280×860, cropped.

Before After
Edit prompt Before: a textarea and model picker; the environment is fixed After: the New thread composer, project locked, Project default
Environment No control After: Project default (david · Worktree), Project checkout, Worktree, Reuse existing
Worktree branch No control After: new or existing worktree, branch from main, dev or feature/cart
Saved After: Worktree on david · from dev, Automation updated
Reopened After: the editor restores Worktree, Branch from: dev
Worktree from dev, created by the CLI Before: New worktree, branch dropped After: Worktree on david · from dev
Its provider uninstalled Provider environments could not be stored After: Environment unavailable banner

AGENT GENERATED

…ry host has no source

A project-default thread always resolved on the primary host, so a project
whose only source lives on another machine failed with 404 "Project has no
local-path source for host". When the primary host has no source of the
project, use the persistent machine that holds its default source, or its
oldest source on a persistent machine. Projects with a source on the primary
host keep today's placement; an offline project machine fails with 502
instead of moving the thread.

Fixes get-bb#4446
A project had no default environment. The root composer remembered the last
environment per browser, while threads created without one (automations,
tasks presets, `bb thread spawn` with no environment flag) always got a
worktree on the primary host, so "Project default" matched neither.

Store a per-project default environment, set from Project settings, the CLI
(`bb project default-environment`) or the API. The composer starts in it; a
pick made in the composer lasts for that tab's draft. Threads created
without an environment start in it too, a Project checkout default giving
each its own worktree on that machine. An unusable default refuses thread
creation with 409 and is reported on the project, instead of silently
falling back.
An automation's editor changed only its prompt and model. Where each run
worked was fixed at creation by CLI flags, and the plugin could not store a
provider environment (a worktree from a named branch, a composition such as
berth, a checkout on another machine) or agent options.

Edit prompt now opens the SDK's experimental_NewThreadComposer, the New
thread screen's own component, seeded with the stored execution. Six
optional props let a plugin edit a saved request: a locked project, a
Project default entry, an in-memory draft, no attachments, seeded agent
options and no plugin customizations. The automation stores the composer's
environment and agent options as threads.spawn takes them, refuses on save
what every run would fail on, and `bb automation create|update` gains the
same choices.
The SDK's bundled declarations include the project schemas, which now carry
defaultEnvironment and defaultEnvironmentProblem. 0.6.65 is already on npm,
so the npm version guard refused to republish it with different types.
get-bb#6055 now ships 0.6.66 with the project default environment types, so the
composer props this branch adds need the next version, and the automations
plugin that uses them requires it.
Main moved the SDK to 0.6.67 (get-bb#6048, get-bb#6051), so this branch's own type
changes need the next version.
get-bb#6055 now carries main and ships 0.6.68, so the composer props this branch
adds need 0.6.69, and the automations plugin that uses them requires it.
Tests (plugins) failed in plugins/connect-next/src/frp-e2e.test.ts:394,
which this branch does not touch: frpc reported "read: connection reset by
peer" where the test only accepts connection refused, EOF or dial. The same
code passed on main and on get-bb#6055, and three local runs pass.
Main already carries "Start project-default threads on the project's
machine when the primary host has no source" (get-bb#6054) and "Show why an
automation failed" (get-bb#6005); the merge keeps their code and adds this
branch's project default environment on top. The project default
environment entry in docs/api_to_audit.md follows main's new entries.
Main's failed-run story (get-bb#6005) renders AutomationDetailView, which now
requires projectDefaultEnvironment.
Main moved PromptBoxInternal into the bundled Composer plugin (get-bb#6122):
the suppressed send-menu test now renders ComposerBox inside the
composer test providers, and the dispatchThroughEditorTarget helper main
removed stays removed. Main also carries "Show why an automation failed"
(get-bb#6005), so its failed-run story passes the environment catalog the
detail view now takes. The Automations plugin requires plugin SDK
0.6.75.
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 23, 2026
…nment-composer

Pick up get-bb#6055 and get-bb#6056 merged with main, with the plugin SDK at 0.6.75.
ymichael added a commit that referenced this pull request Nov 3, 2026
## Human comments

## What was wrong

The Automations CLI copies core's thread-spawn helpers, and the copies
drifted. Its path check missed Windows paths (#4659), so `--environment
C:\repo` was saved as an environment id. `--new-environment` and
workspace paths picked the first host matching a `connected` field that
doesn't exist, then any connected host, then `hosts[0]` even when
offline. Core uses the CLI's own machine. `--at 2026-12-01` was read as
UTC midnight, but core rejects a date with no time as ambiguous.

## What changed

`plugins/automations/src/cli.ts` only:

- The path check uses core's rules: a backslash or a leading drive
letter makes the value a path.
- New environments and workspace paths run on the calling thread's
machine, falling back to `primaryHostId`. This reuses the thread-host
lookup that `--script-file` already had. The old host-list scan is
deleted.
- A date-only `--at` is rejected. Other `--at` values parse as before.
- The `--environment` help text now says where a path runs.

No plugin SDK, host-daemon protocol, or RPC contract changes. Open #6056
makes the same default-machine change as part of a larger feature;
whichever lands second will need a small conflict fix in `cli.ts`.

## How you verified

New tests in `server-harness.test.ts` failed before the fix and pass
after:

- `--environment C:\repo` and `--new-environment worktree` from a thread
land on that thread's machine. Before, the path was saved as `reuse` and
the worktree went to the first connected host.
- A date-only `--at` is rejected. Before, it was accepted.

Three existing expectations moved from the first connected host to the
primary host, so they now cover the no-thread fallback. `pnpm exec turbo
run test typecheck lint --filter=bb-plugin-automations` passes: 166
tests; lint has 0 errors and 4 warnings, all pre-existing in other
files.

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

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot closed this Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

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