Skip to content

Add project folders and environment folders to the agent's writable workspace - #8007

Merged
ymichael merged 11 commits into
mainfrom
bb/multi-folder-projects-c4-project-folders-p1-envi-thr_8jcx8be9cp
Nov 23, 2026
Merged

ymichael merged 11 commits into
mainfrom
bb/multi-folder-projects-c4-project-folders-p1-envi-thr_8jcx8be9cp

Conversation

@ymichael

@ymichael ymichael commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

#7994 made the server decide each session's extra writable folders, but the list was hard-coded to [] in thread-runtime-config.ts. A project could not name folders outside its checkout, and an environment provider had no way to report folders it created. Live testing also showed that the write roots sent on each turn could not narrow a running session in either provider. Claude Code's applyFlagSettings adds new allowWrite entries but never removes them. Codex keeps the write grants from thread start in its persisted thread settings, and a thread/resume restores them alongside the narrower turn sandboxPolicy. So removing a folder would have left it writable for the rest of the session.

What changed

C4, project folders (shared checkouts every thread on a machine sees, read before every turn)

  • DB. New table project_source_folders (id, project_source_id FK cascade, path, sort_key, created_at, unique (source, path)), migration 0166_project_source_folders. Migration-test rewind helper dropProjectFolderSchema.
  • Server API. GET|POST /projects/:id/sources/:sourceId/folders, PATCH …/folders/:folderId (change the path, same rules as add; the folder keeps its id and position) and DELETE …/folders/:folderId. Validation on add: the path must be absolute and match the host's platform. It must not be the checkout, be inside it, or contain it, and must not already be listed (409). The host must confirm it exists via host.paths_exist (400 path_not_found). At most 64 folders.
  • SDK sdk.projects.sources.experimental_folders.{list,add,update,remove} (experimental; new docs/api_to_audit.md entry). CLI bb project folder list|add|update|remove <projectId> [path-or-id] [new-path] [--machine], defaulting to the local machine's checkout. UI: project settings have one Folders section (it replaces Checkouts): each machine lists its main folder (the checkout, marked "main", with Change folder and Remove checkout) first, then its extra folders indented under a hairline (name, full path, "Not found" when missing; Change folder and Remove folder), then a quiet "+ Add folder" row (native picker on the local machine, otherwise the path dialog). A machine without a checkout keeps its Set up button. bb project folder list prints the main folder first; --json lists the extra folders only. Guide chapter bb-guide-projects.md and the skill's command-index.md are updated.

P1, environment folders (that environment's own copies, fixed at create)

  • environments.additional_paths json string[] default '[]', exposed as Environment.additionalPaths and shown as Folder: lines in bb environment show.
  • PluginEnvironmentProviderCreateResult gains optional additionalPaths (no nested prefix; new entry in docs/api_to_audit.md; plugin SDK 0.6.186 → 0.6.187). environment-engine.ts stores it from both create and restore. It uses the same rules as project folders; a violating result fails the create. Omitting it on a reused environment keeps the recorded list. The built-in Worktree and Project checkout providers go through the same path and return none today.

Session folder list. resolveThreadRuntimeCommandConfig merges the project's folders for the thread's machine with the environment's folders, then drops duplicates and the main folder. This runs at every session start, turn and steer.

Daemon and providers. HOST_DAEMON_PROTOCOL_VERSION 277 → 278 because host.read_workspace_agent_context folders gain exists. turn.submit now resolves write roots from its own additionalWorkspaceFolders, and runTurn/steerTurn take them (previously roots were pinned at session start).

The two questions

  1. Do folder changes reach running sessions? Not on their own; this PR makes them. Write access now follows the list at every new turn:
    • Additions apply live in both providers.
    • On a removal, the Claude Code bridge rebuilds its SDK session before the next turn, resuming the same conversation.
    • On a removal, the Codex bridge forks the thread from its rollout. A resume is not enough because Codex restores the persisted grants. The bridge tracks every root granted in the session, plus the roots Codex reports restoring (sandbox.writableRoots in the thread/resume response). That covers sessions closed by the idle sweep or a restart and resumed later, and resumes that happen inside a turn. The fork keeps the conversation: verified live, the agent still knew its earlier file name. Forks request excludeTurns, so Codex's "Full-history hydration is deprecated" notice no longer reaches the timeline.
    • ACP agents (OpenCode, Cursor, …) receive the folders as additionalDirectories at session start and enforce writes with their own permissions. Verified live with OpenCode: after a removal it still wrote into the folder without asking. The ACP bridge now rebuilds a restorable session (session/load/session/resume) before the next turn when the list changes; after the fix OpenCode asks for approval instead. bb's own check on ACP fs/write_text_file already followed the list per turn.
    • Pi runs with full access only, so the folders only inform it (verified live: it gets the folder block and can write anywhere).
    • A steer can't remove access mid-turn; the next new turn does.
    • The agent's instructions list the folders as of session start. A running session may still name a folder added or removed since. Rebuilding the session to refresh instructions would also restart it whenever any plugin's dynamic instructions change, so I left that out.
  2. Missing folder at session start: your recommendation, implemented. The thread starts. The instructions mark the folder "missing on this machine, so you cannot use it this session". It is left out of the write roots. The timeline shows one "Folders missing on this machine" notice, repeated only when the missing set changes (in-memory, per server process).

How you verified

Live, pnpm start:worktree from this branch with an isolated data dir, real Claude Code and Codex (codex-cli 0.171.0), accept-edits:

  • CLI validation: bb project folder add refused the main folder, a subfolder of it, its parent, a duplicate, a missing path and a relative path with the expected messages.
  • Claude Code: turn 1 quoted the "You are working across these folders" block with the folder, wrote into it, and a never-granted control folder was denied. After bb project folder remove, turn 2 got touch: …/extra/cl-2.txt: Operation not permitted. Before the bridge fix, the same turn still wrote the file.
  • Codex: turn 1 wrote into the folder. After removal, turn 2 got Operation not permitted. Before the fix it still wrote, and the rollout's thread_settings_applied showed the persisted grant.
  • Missing folder: a thread started with a deleted folder shows the timeline notice and the "missing on this machine" line in its instructions.
  • Codex after a restart: turn 1 wrote into the folder; the folder was removed and bb restarted, which closed the session. Before the resume fix, turn 2 still wrote the file (cx-r2.txt), and the rollout's resumed thread_settings_applied still listed the folder. After the fix, turn 2 got Operation not permitted, the thread moved to a forked Codex thread id, and the agent still named its turn-1 file.
  • Two machines: a second enrolled daemon (dev-vm) with its own checkout and folders; the Folders section lists both machines, Change folder on dev-vm goes through the path dialog, and with dev-vm offline its Add folder and Change folder are disabled. bb project folder list --machine dev-vm prints its main folder first.
  • Codex full → accept-edits: a thread started in full access, switched to accept-edits, was blocked writing outside its folders both in the running session and after a restart (the resume does not restore full access).
  • Settings UI (headless browser): Change folder in a row's menu repoints it, Remove folder deletes it, and Add folder adds one through both the native-picker path and the in-app dialog. bb project folder update repoints a folder and refuses a path inside the checkout. A folder missing on its machine shows "Path not found", like checkouts.

Tests (pnpm exec turbo run test for each package):

  • public-project-source-folders.test.ts: add, list, change and remove; a change applies the add rules to the new path; overlap, duplicate and missing-path refusals; cascade on checkout removal.
  • thread-runtime-config.test.ts: project and environment folders merged and deduped; missing folders left out of the writable list and noticed once, then again after they reappear and vanish.
  • provider-orchestration.test.ts and thread-environment-restore.test.ts: additionalPaths stored from create and restore; an overlapping path fails the create.
  • runtime.command-contract.test.ts: a turn sends the roots it was submitted with.
  • thread-dispatch.test.ts: turn.submit re-resolves roots per turn.
  • Claude bridge: a removed root rebuilds the session with the narrowed sandbox.
  • ACP bridge.test.ts: a restorable session is rebuilt with the new additionalDirectories only when its folders change (fails without the fix).
  • Codex bridge.session-signature.test.ts: an addition keeps the session, and a removal forks with narrowed writable_roots. A resumed session whose restored roots include a folder bb no longer grants forks before its first turn, and one whose restored roots match does not. The first case fails without the fix.
  • Daemon workspace-agent-context.test.ts and the contract tests.

Results:

  • Typecheck and lint: pnpm exec turbo run typecheck lint --filter='...[origin/main]' passes.
  • Suites, all green: @bb/server (4434), @bb/host-daemon (898), @bb/agent-runtime (314), @bb/db (756), @bb/cli (1418), @bb/app (7346), @bb/sdk, @bb/thread-view, @bb/host-daemon-contract, bb-plugin-provider-claude-code (460), bb-plugin-provider-codex (623).

Merged with main; plugin SDK is now 0.6.187. Migration 0166 is still free on main.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 11 commits November 21, 2026 20:52
…orkspace

Project folders (`bb project folder add|remove|list`, project settings) are
extra checkouts every thread of a project on a machine can read and write,
read before every turn. Environment providers can report their own extra
folders through `additionalPaths` on the create/restore result. The server
merges both into the session's folder list; the daemon re-resolves write
roots each turn, and the Claude Code and Codex bridges rebuild the session
when a root is removed so access is revoked by the next turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cts-c4-project-folders-p1-envi-thr_8jcx8be9cp

# Conflicts:
#	apps/server/src/services/environments/environment-engine.ts
#	packages/domain/src/plugin-sdk-version.ts
#	packages/plugin-sdk/package.json
…ders in settings

A resumed Codex thread restores the writable roots it persisted at start, so a
folder removed while the session was closed (idle sweep or restart) stayed
writable. The bridge now records the roots Codex reports restoring and forks
before the next turn when any of them is no longer granted, including after an
in-turn resume. Forks also request excludeTurns, which stops Codex's
full-history deprecation notice from reaching the timeline. Project settings
mark a folder that is missing on its machine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each folder is now its own row (name, full path, Path not found when missing)
with Remove in an overflow menu, and Add folder moves to the section header,
offering a machine choice when the project has several checkouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s path

Project settings list each machine with its folders indented under a
hairline, a menu on every folder to change or remove it, and a quiet
Add folder row last. Changing a folder goes through a new
PATCH /projects/:id/sources/:sourceId/folders/:folderId route, exposed as
sdk.projects.sources.folders.update and bb project folder update, with the
same path rules as adding one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cts-c4-project-folders-p1-envi-thr_8jcx8be9cp

# Conflicts:
#	packages/domain/src/plugin-sdk-version.ts
#	packages/plugin-sdk/package.json
…CP sessions when the folders change

Project settings now have one Folders section: each machine lists its main
folder (the checkout, with its existing actions) first, then its extra
folders and an Add folder row. `bb project folder list` prints the main
folder first; --json still lists the extra folders only.

ACP agents such as OpenCode receive the extra folders as additionalDirectories
when their session starts and enforce writes themselves, so a removed folder
stayed writable for the rest of the session. The ACP bridge now rebuilds a
restorable session before the next turn when the folder list changes.

The projects guide notes how each provider enforces the folders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cts-c4-project-folders-p1-envi-thr_8jcx8be9cp

# Conflicts:
#	packages/domain/src/plugin-sdk-version.ts
#	packages/plugin-sdk/package.json
sdk.projects.sources.folders becomes experimental_folders, with an
api_to_audit entry for its behaviour, core callers and open questions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 891ceb1 into main Nov 23, 2026
55 checks passed
@ymichael
ymichael deleted the bb/multi-folder-projects-c4-project-folders-p1-envi-thr_8jcx8be9cp branch November 23, 2026 21:49
ymichael added a commit that referenced this pull request Nov 24, 2026
… them up and keep them warm (#8065)

## Human comments

## What was wrong

#8007 added `additionalPaths` so an environment provider can give a
thread extra folders, but no provider returned any, and nothing let an
environment take a project folder out of the thread's workspace. A
worktree thread in a multi-folder project could only branch the main
repository: every other repository in `bb project folder` stayed a
shared checkout that all threads wrote to. Setup scripts also ran only
in the main workspace, and warm worktrees could not carry extra
repositories.

## What changed

**Core contract (experimental, documented in `docs/api_to_audit.md`).**
- `additionalPaths` becomes a list of `{ path, replaces? }` entries
(domain: `replaces: string | null`, filled once when the create result
is parsed). `replaces` names the project folder an entry stands in for.
`mergeWorkspaceFolderPaths` (`workspace-folder-paths.ts`) is the one
place that builds the session's folders: project folders minus the
replaced ones, plus each entry's `path`. A replaced folder stays out
even when its replacement is missing, so a thread never falls back to
writing the shared checkout. Migration 0171 converts recorded
`additional_paths` strings into entries that replace nothing. `bb
environment show` prints `Folder: <path> (replaces project folder
<folder>)`.
- `setup(path, { folders })`: a create can name the extra folders it
made. Core stores them (`environments.setup_folder_paths`, migration
0170), runs each folder's `.bb-env-setup.sh` once, in order, before the
main one (each as its own hook operation, `…:setup:folder:<i>`), and
runs teardown in the main workspace first, then the folders in reverse.
A create fails if it set up a folder it did not return in
`additionalPaths`. After `adopt`, `folders` may name only folders the
adopted environment recorded: core forgets their finished setup records
(`forgetFinishedEnvironmentHookOperations`) and runs them again, then
the main one. Recovery inspects and acknowledges each folder's hooks.
- Plugin SDK 0.6.197. No daemon wire change: hooks already run per path,
and the daemon still receives the merged folder list.

**Worktree provider (`plugins/environment-git-worktree`).**
- Inputs gain `folders: string[]` (default `[]`). `validate`/`create`
refuse a folder that is not one of the project's folders on that
machine.
- New host RPC `createFolders` (`host/folders.ts`): each folder must be
the top folder of a repository with a commit, and no two (including the
main checkout) may share a git common dir. It makes a worktree of each
folder next to the main one, detached at that repository's default base.
If one fails, everything made is removed.
- Create and restore pass the new folder worktrees to `setup`, so their
setup scripts run before the main worktree's.
- Removal removes every worktree in the environment's directory and
deletes each repository's bb-owned branch under the #7242 rules.
- Picker: "Also branch:" lists the machine's project folders that are
git repositories (`listBranchableFolders`).
- Warm pools: folders are set per machine (each checkout has its own
folder paths), on the settings page under each machine or with `bb
worktree pool folders <project-id> <folder>... [--host <host-id>]`, and
stored next to #8112's per-machine counts. Members are created with
those folders and handed only to a create that branches exactly that
set. On handoff the provider checks each folder worktree like the main
one, fast-forwards any that is behind its remote, renames the
placeholder in every worktree, and calls `setup(main, { folders: moved
})`, so only moved folders (and then the main worktree) are set up
again. Reconcile replaces members whose folder set differs or whose
folder worktree left the placeholder or its base.
- Settings: each machine's folder checkboxes sit under it and are shown
only while it keeps warm worktrees; a chosen folder that is no longer a
git project folder there is flagged. Ladle stories cover every state.

**Storage retention.** An environment's `additionalPaths` count as
bb-owned (never offered as external worktrees), their uncommitted
changes block automatic recovery of an interrupted cleanup, and their
size is added to the leftover worktree's.

**Docs.** README, the worktree skill, the bb guide's environments and
projects chapters, and the plugin-authoring references.

## How you verified

- New and updated tests: `environment-holds.test.ts` (folder setups run
in order before the main one and teardowns in reverse; setup after adopt
reruns only named recorded folders; unrecorded folder refused;
unreturned set-up folder fails the create),
`provider-orchestration.test.ts` (entries canonicalized, relative
`replaces` rejected), `thread-runtime-config.test.ts`,
`environment-additional-path-entries-migration.test.ts`, `host.test.ts`
(real git folder worktrees), `server.test.ts`, `warm-pools.test.ts`
(folder handoff, exact-set matching, fast-forward and re-setup of a
behind folder, reconcile replacement, per-machine folder config),
`storage.test.ts` (folder worktree changes block recovery and folder
worktrees are never external; both fail without the fix).
- `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`
passes; affected package tests pass locally.
- Live on an isolated `pnpm start:worktree` instance with real
repositories whose setup/teardown scripts log their order: a create with
`docs` and `api` ran setup docs → api → app and teardown app → api →
docs, removing every worktree and branch; a warm pool branching `api`
set up api → app, was handed to a thread branching `api` without new
setup and with the branch renamed in both repositories; a thread
branching nothing missed and built fresh; after a push to `api`'s
remote, the handoff fast-forwarded the `api` worktree to the new commit
and reran setup api → app; the settings checkboxes saved per machine.

> AGENT GENERATED

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 24, 2026
…by repo (#8062)

## Human comments

## What was wrong

A thread's git features only know about one repository: the
environment's own path. Since #8007 a thread can also write to project
folders and environment folders, and a main folder is often a plain
folder holding several repos (a "folder full of repos", or a custom
provider's folder of worktrees like 1i2's). In those layouts the Changes
panel showed nothing (the tab is hidden when the main folder is not a
repo) or only the main repo, and the agent's instructions did not say
which folders were repos. Separately, #3905: when the environment's path
is a subfolder of its repo, the git plugin ran git with that subfolder
as the working directory, but the changed-file list is
repo-root-relative, so every patch came back empty and the old/new file
reads used doubled paths.

## What changed

**Finding repos (daemon, raw data).** New host RPC `host.find_git_repos
{ folderPaths, maxDepth, maxRepos }` returns, per folder, whether it
exists, its git top level (`git rev-parse --show-toplevel`) and, for a
folder that is not in a repo, the repos inside it: walked level by level
up to `maxDepth`, skipping hidden folders and
`node_modules`/`vendor`/`dist`/`build`/`target`/`__pycache__`/`venv`,
stopping at each repo (a `.git` directory or file, so linked worktrees
count), deduplicating by real path so symlinks are followed once, and
stopping at `maxRepos` (`truncated`). Each found repo carries the walked
`path` and its resolved `gitRoot`, the same form `git rev-parse
--show-toplevel` gives, so the server can list a repo reached through
two paths once. `HOST_DAEMON_PROTOCOL_VERSION` 282 → 283.

**Repo list (server, in memory).** `resolveEnvironmentRepos`
(`apps/server/src/services/environments/environment-repos.ts`) asks the
host about the main folder plus every extra folder (project folders for
the machine + environment `additionalPaths`, via a helper now shared
with `thread-runtime-config.ts`) with depth 2 and at most 32 repos per
folder, and keeps the result for 10 seconds per environment. Nothing is
stored; no migration, no setting. Each repo has `rootPath` (git top
level), `path` (the folder the thread works in; differs from `rootPath`
for a subfolder), `source` (`main` / `folder` / `discovered`) and
`label`: `""` for the main repo, the path relative to the main folder
for repos inside it, and a `../…` relative path for repos outside it, so
a label can never collide with a path inside the main repo. Hand-added
folder validation is unchanged.

**Public API.** `GET /environments/:id/repos`,
`sdk.environments.experimental_repos({ environmentId })` (also on
`PluginBbSdk`; new `docs/api_to_audit.md` entry naming its core callers;
plugin SDK 0.6.197 → 0.6.201), and `bb environment repos <id> [--json]`
(guide chapter and command index updated). The shape is meant for the
GitHub PR status plugin as the second reader (`rootPath` is the cwd it
needs).

**Instructions.** The "You are working across these folders" block lists
the repos found inside each folder (` - Git repository inside it:
<path>`) and now also appears for a main folder that only holds repos. A
thread whose main folder is a repo and has no extra folders does not
call discovery at all, so single-repo threads see no change. A turn
waits at most 3 seconds for discovery; after that it goes without the
repo lines and the cached result is used next turn.

**Changes panel (git plugin).**
- The server merges every repo's changed files into one list. Each repo
runs git from its own top level (`path: repo.rootPath`), which fixes
#3905: listing, patches and old/new file reads now agree on
repo-root-relative paths.
- Files from repos other than the main one are prefixed with the repo's
label; patches and file sides map the prefix back to the right repo
(`gitDiffRepoPath` / `locateGitDiffRepoPath` in `contract.ts`). The file
card asks for context by its listed path rather than the path inside the
patch text.
- Targets: the main repo uses the selected target. Other repos compare
branch targets against their own default branch; the commit view stays
on the main repo.
- The UI shows a header per repo (name and file count) when there is
more than one repo, and a notice for a repo whose changes could not be
read.
- When the main folder is not a repo but holds repos, the Diff tab now
appears (new `repos` RPC) and shows uncommitted changes per repo.
Committed branch history for that layout is left for later.
- `bb git files` / the status chip / sidebar status are unchanged (main
repo); a single-repo environment's output is byte-for-byte the same.
- Live refresh: groups for folders outside the main path refresh at turn
end (the daemon only watches the environment path); mid-turn edits there
appear after the next refresh.

## How you verified

**Live**, `pnpm start:worktree` from this branch, real Claude Code
threads (accept-edits):
- Plain main folder holding two repos (`api`, `web`) plus a project
folder that is itself a repo (`shared`): the agent appended a line in
each; the Changes panel showed three groups `api`, `web`, `../shared`
with diffs and context loading; the agent quoted the block naming both
repos inside the main folder and the extra folder.
- #8007's layout: a git main repo with an environment folder (set
through `environments.additional_paths`) holding two linked worktrees
plus an `AGENTS.md`: `bb environment repos` listed `(main)`,
`../envfolder/one`, `../envfolder/two`; the Changes panel showed the
three groups; the instructions named both worktrees under the folder.
- #3905: a project whose checkout is `mono/packages/app`: the Changes
panel renders the diff for `packages/app/file.txt` (no "No renderable
diff"), and `bb environment repos` maps it to the `mono` top level.

- Repo reached two ways (macOS `/tmp` is a symlink): project folders
`/tmp/x/envfolder` and `/tmp/x/envfolder/one`. Before the dedupe fix
`../envfolder/one` was listed twice and its file appeared twice in the
Changes panel; now it appears once.

**Tests** (added ones fail before the change):
- `find-git-repos.test.ts` (real repos on disk): stop at repos, skip
hidden/dependency folders, symlink dedupe, subfolder of a repo, missing
folder, linked worktrees, `maxRepos` truncation, a repo found through a
symlinked folder reported at the same root as the repo itself.
- `public-environment-repos.test.ts`: labels, order, dedupe of a folder
in the main repo, dedupe of a repo reached through a symlink and as an
extra folder, missing folder, caching.
- `thread-runtime-config.test.ts`: repos named under their folder; no
discovery call and no block for a single-repo thread.
- Git plugin `server.test.ts`: merged list with per-repo targets,
patches read from each repo, file side read from the repo root for a
subfolder (#3905); `DiffFilesPanel.test.tsx` repo headers;
`DiffFileCard.contextExpansion.test.tsx` context by listed path.
- Suites: `@bb/server` (4465), `@bb/host-daemon` (901), `@bb/cli`
(1422), `@bb/sdk` (135), `@bb/host-daemon-contract` (95),
`@bb/templates` (47), `bb-plugin-bb--git` (297); `pnpm exec turbo run
typecheck lint --filter='...[origin/main]'`.

Fixes #3905

> AGENT GENERATED

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 25, 2026
## Human comments

## What was wrong

Since #8007 a thread's agent can read and write the project's folders on
its machine and the environment's `additionalPaths`, but the composer's
@-mention search only looked in the main folder. `GET
/environments/:id/paths` and `GET /projects/:id/paths` each ran one
`host.list_paths` on the main folder, and results carried a path
relative to it. Files in the other folders could not be mentioned,
though the agent could open them.

## What changed

**Server.**
- `searchWorkspaceFolderPaths`
(`apps/server/src/services/projects/workspace-path-search.ts`) sends one
`host.list_paths` with the main folder and every extra folder as
`rootPaths`. The extra folders are the project's folders for the machine
plus the environment's `additionalPaths`: the same list the server
builds for the agent. Both the turn's runtime config and the path routes
get it from `listEnvironmentExtraFolderPaths`, so search and the agent's
folders cannot drift.
- It maps each result's `rootPath` to `folderPath` (`null` for the main
folder). A `folders=extra` search with no extra folders returns empty
without calling the host.
- Both path routes use it. The project route (used by the new-thread
composer before an environment exists) searches the project's folders
for the chosen machine.

**Daemon.**
- `host.list_paths` takes `rootPaths: string[]` (1–100) instead of
`path`, and each entry carries its `rootPath`. The daemon lists every
root in parallel, skips roots that do not exist, and ranks all
candidates in one pass under one limit, so a search is one round trip
however many folders the thread has, and scores are comparable across
folders.
- Ranking every root in one pass merges matches by item, not by relative
path (`mergeRankedMatches` in `@bb/fuzzy-match`). Before this,
`README.md` in three folders returned one result, because matches with
the same path string were treated as one.
- `host.list_paths` takes `followRootSymlink`, like `host.list_files`.
Workspace folder search sets it, so a symlinked extra folder is searched
through its target. Without it, the daemon rejected the whole search,
and one symlinked folder hid every extra-folder result. The files and
thread storage routes keep `false`.
- The thread storage route drops `rootPath` from its response (unchanged
shape). `POST /files/paths` passes the daemon result through, so it now
also returns `rootPath`.
- `HOST_DAEMON_PROTOCOL_VERSION` 283 → 284.

**Contract and SDK.**
- Each result gains `folderPath`: `null` for the main folder, otherwise
the absolute folder its relative `path` belongs to
(`WorkspaceSearchPathEntry`).
- Both routes take an optional `folders` query, `main` or `extra`.
Absent means all folders.
- `sdk.environments.paths` / `sdk.projects.paths` pass it through.
- Plugin SDK 0.6.201 → 0.6.202.

**CLI.**
- `bb environment paths` prints results from an extra folder as absolute
paths. `bb project paths` prints JSON, which carries `folderPath`.

**Composer.**
- `usePathSuggestions` sends the main-folder query and a separate
`folders=extra` query, and merges them as they arrive. Main-folder
results appear as fast as before, and extra-folder results join when
ready. The extra-folder query counts toward the menu's loading and error
state, so the menu does not say "No matching mentions" while
extra-folder results are still loading or after they fail.
- A result from another folder becomes its absolute path. The mention
chip inserts `@/abs/path`, which the agent opens directly, and the menu
shows the folder as the result's secondary text.
- Clicking such a chip in the timeline or a new-thread draft opens it as
a host file preview (`ThreadDetailView`, `RootComposeView`), since
workspace previews only take relative paths.

**Not changed.**
- The secondary panel's "open file" search (`useFileSearchSuggestions`)
still searches the main folder and thread storage only
(`includeExtraFolders: false`). Its workspace preview tab cannot open
absolute paths.
- #7633 (completing any absolute path) does **not** fall out of this.
Search covers the thread's folders, not arbitrary paths, and typing
`/Users/...` still gives no completion. It needs a separate
directory-browsing completion.

## Performance

Measured on a real multi-folder project: the main folder is a bb
checkout (about 9,000 files), with extra folders `t3code` (about 32,500
files) and `bb-plugins`. Requests used the composer's settings
(`limit=16`, files and directories) against a `pnpm start:worktree`
server, 12 runs per query after a warm-up. The machine was heavily
loaded (load average 232–465), so absolute numbers are noisy; compare
columns.

| query | main folder only (what main does), p50 / p95 ms | composer
first results (main, sent alongside extra), p50 / p95 | all folders in
(main + extra), p50 / p95 | one combined request, p50 |
|---|---|---|---|---|
| readme | 45 / 117 | 64 / 98 | 414 / 1245 | 340 |
| package.json | 57 / 137 | 62 / 111 | 149 / 238 | 171 |
| server | 141 / 273 | 114 / 206 | 522 / 594 | 449 |
| promptbox | 33 / 126 | 34 / 169 | 133 / 194 | 114 |
| usepath | 24 / 101 | 18 / 47 | 50 / 104 | 50 |
| zzqx (no match) | 8 / 13 | 9 / 31 | 54 / 108 | 51 |

The first version sent one combined request. Because the daemon ranks
large listings on one serial lane, main-folder results waited for the
32k-file folder, and in that first measurement the warm p50 for common
queries went from about 210–330 ms (main folder only) to 1.3–2.6 s.
Splitting the request keeps the first results at main-only speed.
Extra-folder results add 50–520 ms p50, depending on how many entries
the query matches.

The table was measured when the server still sent one `host.list_paths`
per folder. Moving the multi-folder search into the daemon leaves the
daemon's work about the same, and saves one host round trip for each
extra folder beyond the first, which is about 180–250 ms per round trip
on a remote host over bb Connect. Daemon-only timing on the same
`t3code` + `bb-plugins` extra folders (`limit=48`, 15 runs, load average
about 60):

| query | one call per folder, in parallel (p50 / p95 ms) | one
multi-root call (p50 / p95 ms) |
|---|---|---|
| readme | 671 / 978 | 628 / 1074 |
| package.json | 304 / 371 | 274 / 391 |
| server | 865 / 1308 | 857 / 1492 |
| promptbox | 219 / 355 | 219 / 685 |
| usepath | 124 / 424 | 149 / 184 |
| zzqx (no match) | 84 / 240 | 101 / 227 |

## How you verified

**Live, same-named files and symlinked folders** (`pnpm start:worktree`,
new-thread composer). The project has a main folder plus extra folders
`extra-lib`, `extra-two`, and `linked-three`, which is a symlink. Each
folder has a `README.md`.
- `@readme` lists all three READMEs, one per folder. Before the fix it
listed two, and the API returned one for all folders together.
- `@yak` finds `yak-notes.md` in the symlinked `linked-three`. Before
the fix, adding that folder made `@zebra` (in `extra-lib`) show "No
matching mentions", and the API returned `invalid_path ... must not be a
symlink`.

**Live** (`pnpm start:worktree`, real Claude Code thread, Accept Edits),
on the multi-folder project above:
- Typing `@turbo.json` lists the main folder's `turbo.json`, then
`turbo.json /Users/michael/Projects/bb-plugins` and other files from
`bb-plugins` with their folder path.
- Selecting the `bb-plugins` file inserts a `turbo.json` chip. The sent
message is `@/Users/michael/Projects/bb-plugins/turbo.json …`, and the
agent read the file and replied with its first line.
- Clicking the chip in the timeline opens
`/Users/michael/Projects/bb-plugins/turbo.json` in the side panel.
- The new-thread composer for the project lists `bb-plugins` results
too.

**Tests:**
- `public-environments.test.ts`: the environment route sends the main
and extra folders in one `host.list_paths`, maps `rootPath` to
`folderPath`, honours `folders=main|extra`, and skips the host when
there are no extra folders. The project route with `hostId` searches the
project's folders.
- `workspace-path-list.test.ts` (daemon, real temp folders): roots are
ranked together under one limit, each result names its root, and a
missing root is skipped.
- `workspace-path-list.test.ts`: a file at the same relative path in
three roots comes back three times, with and without a query. A
symlinked root is searched with `followRootSymlink: true` and rejected
with `false`.
- `fuzzy-match` `index.test.ts`: distinct items that share a path are
all returned. This test fails without the matcher change.
- `usePathSuggestions.test.ts`: results from another folder become
absolute paths and keep their folder.
- `environment.test.ts` (CLI): `bb environment paths` prints an
extra-folder result as an absolute path.
- Suites: `@bb/server`, `@bb/app`, `@bb/sdk`, `@bb/cli`,
`@bb/server-contract`, plus `pnpm exec turbo run typecheck lint
--filter='...[origin/main]'`.

> 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.

1 participant