Skip to content

One description of a workspace: subfolder-aware status and shared base-branch choice - #6193

Closed
ymichael wants to merge 9 commits into
mainfrom
bb/swing-7c-one-stored-workspace-descriptor-thr_aix5mkmch4
Closed

ymichael wants to merge 9 commits into
mainfrom
bb/swing-7c-one-stored-workspace-descriptor-thr_aix5mkmch4

Conversation

@ymichael

@ymichael ymichael commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

About a dozen places each worked out a workspace's repository root, branch and base branch separately, and they disagreed. Git commands ran in the environment folder, while diff and status paths are relative to the repository root. So a project in a subfolder of a repository got an empty or wrong diff, and its changed files would not open. Base-branch selection was copied between the worktree plugin and the server. A bare --base-branch main used the local main even when it was behind origin/main.

What changed

  • One description of a workspace. describeHostWorkspace in packages/host-workspace is now the only code that builds a workspace's path, repository root, branch and default branch. environment.attach, the workspace watcher and the new host.describe_workspace command all use it. Repository root and folder prefix come from git rev-parse --show-toplevel and --show-prefix, read separately so a folder name containing a newline can't be misparsed. Workspace git operations run at the repository root. Discovery now runs on the shared bb-environment-provider-host git runner, which gains host-workspace's bounded retry for silent Windows STATUS_DLL_INIT_FAILED startup crashes; without it, a transient crash could report a repository as non-Git.
  • Status carries the location. WorkspaceStatus gains a required repository: { root, workspacePrefix }. In the thread view, a changed file inside the environment folder opens in the normal preview tab. A file elsewhere in the repository opens as a host file. "Open in editor" uses the same mapping.
  • Diff panel in subfolder projects. The diff panel and the Info changes list pass repository-relative paths. Clicking a filename now opens files inside the environment folder in the workspace preview, and files elsewhere in the repository as host files; before, both showed File not found. Copy path now joins paths to the repository root instead of the environment folder.
  • Base branch. The worktree plugin and the server now share one selectWorktreeBaseBranch (bb-environment-provider-host/base-branch):
    • a bare branch name uses origin/<name> when local is equal to it or behind;
    • it keeps local when local has commits origin lacks, has diverged, or the relation is unknown;
    • explicit refs are used exactly.
      --base-branch help in bb thread spawn and bb thread fork describes this rule.
  • New SDK and CLI surface. PluginBbSdk.environments.experimental_describeWorkspace and bb environment workspace <id>, with entries in docs/api_to_audit.md, the Plugin Guide and the CLI command index.
  • Plugin-safe provider host. bb-environment-provider-host no longer imports @bb/domain. The plugin host build rejects that import, so the git-worktree, project-checkout and GitHub PR status hosts would not have built. A new plugin-build test builds those three hosts.
  • Cleanups. Removed cross-package re-exports from host-workspace, and the unread descriptor fields in daemon test fakes.

Wire changes:

  • HOST_DAEMON_PROTOCOL_VERSION goes from 252 to 253, for the new host.describe_workspace command and the required repository field on the workspace.status result.
  • The bundled SDK types change. They ship in @get-bb/plugin-sdk 0.6.83: main has bumped to that version and it is not published yet.

How you verified

  • pnpm exec turbo run typecheck lint --filter='...[origin/main]': 146/146 pass.
  • oxfmt --check passes on changed files.
  • The npm version guard passes.
  • pnpm install --frozen-lockfile passes.
  • pnpm exec turbo run test --filter='...[origin/main]'. Under full parallel load, Pi provider timeouts and two server plugin-loading tests failed; all of them pass when re-run alone. @bb/desktop's Electron preload smoke test times out the same way on a clean origin/main checkout.
  • Tests added:
    • the plugin host build test, which fails on the previous code;
    • a subfolder provisioning test that asserts the repository root and packages/app/ prefix in status;
    • locateRepositoryFile cases, including the packages/application/ near-miss;
    • selectWorktreeBaseBranch cases;
    • shared-runner retry tests: a silent startup crash still discovers the repository, and retries stop after three attempts;
    • a provisioning test for a subfolder whose name contains a newline (skipped on Windows).
      The retry and newline tests fail on the code before the fix.
  • Workspace discovery on the bb repository: median 60 ms before and 41 ms after (40 runs), with identical output.
  • Manual QA on a pnpm start:worktree instance. The project was the packages/app subfolder of a temporary repository.
    • Status reported {"root":"…/qa-repo","workspacePrefix":"packages/app/"}.
    • Clicking packages/app/inside.txt opened the workspace preview with the right content.
    • Clicking root-level OUTSIDE.md opened a host-file tab at the repository-root path with the right content.
    • After a reload, the thread view made status requests only, with no extra workspace call.

Fixes #3905
Fixes #1917
Related: #3955

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/swing-7c-one-stored-workspace-descriptor-thr_aix5mkmch4 branch 2 times, most recently from f9c0ea3 to e9189bf Compare October 23, 2026 23:12
ymichael and others added 9 commits October 26, 2026 12:07
bb-environment-provider-host imported @bb/domain, which the plugin host
build rejects, so the git-worktree, project-checkout and GitHub PR status
hosts failed to build. Its types are local again, and a test now builds
those three hosts.

describeHostWorkspace is the only place that assembles a workspace's
path, repository root, branch and default branch; environment.attach,
the workspace watcher and host.describe_workspace all use it. The root
lookup runs alongside repository inspection and branch reads skip a
repeated repository check (median 60 -> 41 ms on the bb repo, identical
output). selectWorktreeBaseBranch is shared by the worktree plugin and
the server instead of two copies.

Also drops cross-package re-exports, the unread HostWorkspace.descriptor,
leftover test fixture junk, and stale --base-branch help.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Workspace status now carries the repository root and the environment
folder's prefix within it. The thread view uses that to open a changed
file immediately: files inside the environment folder open in the normal
workspace preview tab, files elsewhere in the repository open as host
files. Open in editor uses the same mapping and falls back to the
environment folder until status arrives. The thread view no longer
fetches the workspace description.

detectGitRepoKind is back to a single rev-parse that returns "none" on
failure; the full inspection runs only when attaching a folder and for
linked-worktree detection.

The revision-file route test now answers host.describe_workspace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
git rev-parse --show-toplevel prints forward slashes on Windows, so the
root no longer matched the environment path's form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The diff panel and Info changes list pass repository-relative paths, but
the preview opened them relative to the environment folder and Copy path
joined them to it, so a subfolder project showed File not found and
copied a doubled path. Files inside the environment folder now open in
the workspace preview, files elsewhere in the repository open as host
files, and diff cards copy paths from the repository root.

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

Workspace discovery moved onto the shared provider-host Git runner, which
lacked host-workspace's retry for silent STATUS_DLL_INIT_FAILED startup
crashes, so a transient crash could classify a repository as non-Git. The
runner now retries those crashes the same bounded way.

readWorkTreeLocation split combined --show-toplevel/--show-prefix output at
its last newline, which misparsed subfolder names containing newlines. It now
reads the two values with separate commands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/swing-7c-one-stored-workspace-descriptor-thr_aix5mkmch4 branch from 5f168ef to 500550d Compare October 26, 2026 19:11
@ymichael

Copy link
Copy Markdown
Collaborator Author

Superseded. #6165 rebuilt git reads and the shared git runner on main, which replaced this PR's git-helper consolidation, Windows retry and priority handling, and moved the code the subfolder fix touched into the Git plugin. The base-branch rule (#1917) and non-git parent environment reuse moved to #6336. The subfolder diff fix (#3905) will be redone inside the Git plugin after #6157 lands.

AGENT GENERATED

@ymichael ymichael closed this Oct 26, 2026
ymichael added a commit that referenced this pull request Oct 26, 2026
…folders (#6336)

## Human comments

## What was wrong

`bb thread spawn --base-branch main` passed `main` to `git worktree add`
unchanged. When the local `main` was behind `origin/main`, the new
worktree started from the stale local commit. Only names that already
began with `origin/` were fetched first. The default base (no
`--base-branch`) already compared local with origin; named branches
skipped that comparison.

Separately, a child of a live thread in a project whose folder is not a
Git repository always asked the git-worktree provider for a fresh
worktree on the parent's machine. That fails, because there is no
repository to make a worktree of.

This is the part of #6193 that still applies after #6165. #6165 rebuilt
git reads and the shared git runner on main, which replaced the rest of
#6193.

## What changed

- **Named bases use the default-branch rule**
(`plugins/environment-git-worktree/host/base-branch.ts`):
- a bare branch name uses `origin/<name>` when local is equal or behind;
  - it keeps local when local is ahead, diverged or unknown;
  - it uses the remote when only the remote branch exists.
  
Explicit remote names such as `origin/main` and `refs/...` paths are
used exactly. The selected remote base is fetched before creation, as
before.
- **The default base is always returned and stored.** Before, the
resolver returned `null` when the result equaled the local default, and
`createWorktree` re-read the repository default. `defaultBaseBranch` and
`create` now share one resolver.
- `readBranchRelation` (previously the private
`readDefaultBranchRelation` in
`bb-environment-provider-host/workspace-git`) is exported, so the plugin
can compare any local/remote branch pair.
- **Non-git parent reuse**
(`apps/server/src/services/threads/thread-default-policy.ts`): a child
of a live thread in the same project reuses its parent's environment
instead of requesting a worktree. This applies only when:
- the child asked for the project default, or the implicit host default
on the parent's machine;
  - the parent's environment is ready;
- the environment is not a Git repository and its path is not owned by a
provider.
- **Docs:** the `--base-branch` help in `bb thread spawn` and `bb thread
fork`, the threads guide and the worktree plugin README describe both
rules.

No wire changes and no SDK changes.

## How you verified

- `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`:
123/123 pass.
- `pnpm exec turbo run test` for the git-worktree, project-checkout and
Git plugins, `bb-environment-provider-host`, `@bb/cli` and
`@bb/templates`: all pass. The server's `thread-default-policy` and
`worktree-base-branch` tests pass.
- Tests added. Against main's code, the stale-base and reuse tests fail
and the rest pass:
- `host.test.ts`: a stale local `main` or `release` now starts from the
remote commit. `origin/main` is used as the remote. `refs/heads/main`
keeps the local commit. These fail on main for `main` and `release`.
- `host.test.ts`: local commits are kept when local is ahead or
diverged, for `main`, `release`, `refs/heads/main` and the default base.
These guard against the new rule dropping local work.
- `thread-default-policy.test.ts`: implicit project-default and host
children of a non-git parent reuse its environment. Both fail on main.

Fixes #1917

> AGENT GENERATED

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

Co-authored-by: review <review@local>
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

1 participant