Skip to content

Find git repos inside a thread's folders and group the Changes panel by repo - #8062

Merged
ymichael merged 9 commits into
mainfrom
bb/repo-discovery-changes-by-repo-thr_psx98pzvux
Nov 24, 2026
Merged

ymichael merged 9 commits into
mainfrom
bb/repo-discovery-changes-by-repo-thr_psx98pzvux

Conversation

@ymichael

@ymichael ymichael commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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 Diff viewer is empty when an environment's path is a subdirectory of its git repository #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.

  • Add project folders and environment folders to the agent's writable workspace #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.

  • Diff viewer is empty when an environment's path is a subdirectory of its git repository #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 (Diff viewer is empty when an environment's path is a subdirectory of its git repository #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

ymichael and others added 9 commits November 24, 2026 15:26
…ffs from each repo's top level

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…scovery in the test daemon, and cap how long a turn waits for it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…de them replaceable

#8065 turned an environment's additionalPaths into { path, replaces } entries that can replace a project folder with the thread's worktree. Repo discovery now passes those entries to mergeWorkspaceFolderPaths, so it lists the same folders as the thread's instructions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git reports a folder's top level with symlinks resolved, but repos found by walking a plain folder kept the walked path. On macOS, where /tmp and /var are symlinks, a repo reached both as an extra folder and inside another folder was listed twice, so its files appeared twice in the Changes panel. Each found repo now carries its resolved root as gitRoot next to the walked path, and the server dedupes and runs git by that root while labels still use the walked path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/repo-discovery-changes-by-repo-thr_psx98pzvux branch from 5e1aa01 to 6edbdd3 Compare November 24, 2026 23:27
@ymichael
ymichael merged commit 0165810 into main Nov 24, 2026
96 of 97 checks passed
@ymichael
ymichael deleted the bb/repo-discovery-changes-by-repo-thr_psx98pzvux branch November 24, 2026 23:57
ymichael added a commit that referenced this pull request Nov 25, 2026
…ed (#8126)

## Human comments

## What was wrong

While an agent works, the Diff panel cost two host round trips a second,
whether or not the diff changed. The daemon reports
`work-status-changed` for every workspace write without fingerprinting
it (`apps/host-daemon/src/watch-manager.ts`), including identical
rewrites and writes to ignored output. The git server marked both the
`status` and `files` tags stale on every such event and flushed at most
once a second (`plugins/git/server/invalidation.ts`). Each flush made
the client refetch both reads, and each refetch was one
`plugin.host.call`. Every host `files` call also re-ran `diffPatch` for
up to 10 inline patches and shipped them again, though the server and
client already had them at the same revision. This is finding #1 of the
server→daemon RPC audit.

## What changed

The change stays inside the git plugin (server and host ship as one
plugin artifact). There is no daemon wire change, so no
`HOST_DAEMON_PROTOCOL_VERSION` bump.

- **New host method `snapshot`** (`plugins/git/host.ts`, `contract.ts`).
It reads status and every watched file list in one call, sharing one
`git status`.
  - Each part carries a sha256 fingerprint of its result.
- When the server passes the fingerprint it already holds
(`statusUnless`, `files[].unless`) and the result still matches, that
part comes back as `{ outcome: "unchanged" }`. An unchanged file list
also skips `diffPatch`.
- **`knownPatches` on `files` and `snapshot`.** The server names the
inline patches it holds, by path and blob revision. The host reads only
the others and lists the reused paths, and the server fills them back
in. The client contract (`files.initialPatches`) is unchanged.
- **Server flush becomes a probe** (`server.ts`).
- A coalesced `status`/`files` invalidation for a watched environment
now makes one `snapshot` call with the status and the watched file-list
queries.
- The server compares the result with what it served while those reads
were watched, and invalidates only the tags whose result changed. Other
tags (refs, viewed) still publish directly.
- The snapshot replaces the read memo entries, so the client's refetch
is served without another host call.
- Probes for an environment run one at a time; tags that arrive during a
probe go through the coalescer again.
- The turn-end check uses the same probe, and now compares the file
lists as well as status.
- **Several repos (#8062).** The snapshot follows the Changes panel's
repo list: one `snapshot` call per repo folder, carrying that repo's
watched file lists (with each extra repo's own target) and its status,
plus the environment folder's status when no repo is rooted there. A
single-repo environment still makes one call. The merged, repo-grouped
result is compared with what was served, so a changed repo list also
refreshes the panel.
- **Watched file lists keep their memo on change events.** Unwatched
file-list queries are evicted when the workspace changes or their last
watcher leaves. The probe owns their freshness: it drops any in-flight
read and replaces the entry, so a read that started before a change
can't stand in for the check after it. Unwatched environments still
clear on every change. If a probe fails or can't cover a tag, the server
clears the memo before invalidating.
- **Shorter quiet period** (`server/invalidation.ts`). A probe now waits
50 ms of quiet instead of 250 ms, with a 250 ms max wait instead of 500
ms. The 1 s minimum spacing per environment stays, so there is still at
most one host call a second. The long debounce existed to batch client
refetches; a no-op probe now costs a 275 B reply and no refetch, so it
only delayed real edits.
- `server/invalidation.ts` passes the environment id to `publish`.
`DIFF_FILES_INLINE_PATCH_MAX_FILES` moved to `contract.ts`, the schema
that uses it. The README and `PLUGIN_OVERVIEW.md` describe the new
refresh.

Not changed: no-op writes still cost one background `snapshot` per
second. It is answered `unchanged` in 275 B and causes no client
refetch. Filtering earlier would mean host-side change detection. The
daemon's `work-status-changed` has to stay unfiltered, because core's
environment file previews depend on it for ignored files too.

## How you verified

**Real servers, same input** (`af25b0b5a60` vs this branch, fresh `/tmp`
data dirs):
- The workspace was a 9,101-file clone of this repo on a **second
enrolled daemon**. It connected through a WebSocket-aware proxy that
adds **100 ms each way (200 ms RTT)** and logs every daemon↔server frame
by request id.
- The Diff panel was open in headless Chrome: "All changes", 3 changed
files, inline patches.
- Each run lasts 60 s and makes 11 real edits: append a line to one of 3
tracked files, every 5 s plus a random 0–1 s offset. The churn scenario
also writes every 250 ms, alternating an identical rewrite of
`package.json` and a write to a `.git/info/exclude`d directory, which is
about 230 `work-status-changed` events a minute.
- Latency is measured from the edit to the new `+N` count in the panel.
Latency cells are means over the listed runs (each run is 11 edits).
Host-call counts and bytes were identical across runs to within 1 call.
The branch numbers in this table were measured at f0d08f9.

| per minute | main, churn | branch, churn | main, edits only | branch,
edits only |
|---|---|---|---|---|
| git host calls | 122 (61 `status` + 61 `files`) | **61 `snapshot`**
(~50 answered `unchanged`) | 24 (12 + 12) | **12 `snapshot`** |
| git host request bytes | 365 KB | 219 KB | 72 KB | 43 KB |
| git host response bytes | 224 KB | **45 KB** | 44 KB | 32 KB |
| client `status` + `files` refetches | 122 | **22** | 24 | 22 |
| edit → panel, mean (runs) | 603 ms (667, 669, 693, 382) | 625 ms (680,
570) | 744 ms (740, 748) | **590 ms** (590, 589) |

Per action:
- **A real edit:** 2 host calls → **1**, and it shows up **~150 ms
sooner** (744 → 590 ms with 200 ms RTT).
- **A burst of no-op writes:** 2 host calls with full payloads plus 2
client refetches per flush → **1** `snapshot` with a 275 B `unchanged`
reply and no client refetch.

About 3.4 KB of each host request is core's `contributedEnv`, sent on
every `plugin.host.call` (audit finding #9); it is out of scope here.

Latency phases for edits only, mean of 22 edits:

| phase | main | branch |
|---|---|---|
| write → daemon event at proxy | 90 ms | 90 ms |
| event → host request (quiet period + 100 ms one-way) | 362 ms | **158
ms** |
| host round trip | 210 ms | 209 ms |
| host response → panel | 82 ms | 134 ms |

The last row is ~52 ms longer on the branch: after the probe
invalidates, the client makes one more client→server→plugin request,
which the snapshot-seeded memo answers. That cost is fixed and doesn't
grow with host RTT, and the shorter quiet period more than covers it.

Under churn, latency is set by where an edit lands against the 1 s
minimum spacing, which both builds share. Run-to-run spread (382–693 ms
on main) is larger than the difference between builds.

**Tests:**
- `plugins/git/server/invalidation.test.ts`: covers the 50 ms quiet
period, the 250 ms max wait and the unchanged 1 s spacing.
- `plugins/git/server.test.ts` (new "workspace change refreshes" block,
each failing on main):
- one `snapshot` and no invalidation for unchanged bursts, with later
reads served from it;
- only the changed tag is invalidated, and its refetch is served from
the snapshot;
  - the host answers `unchanged` for parts the server holds;
  - a read in flight across a change does not stand in for the probe;
- the host is asked only for patches the server doesn't hold, and the
client still gets the full `initialPatches`.
- `plugins/git/host.test.ts`: against a real repo, `files` and
`snapshot` re-read only patches whose revision changed, and a matching
fingerprint yields `unchanged`.
- Existing turn-end, invalidation and CLI tests are updated for the new
`publish` signature and host output shape.
- `pnpm exec turbo run typecheck test lint:type-aware
--filter=bb-plugin-bb--git` passes locally. Full suites are left to CI.

**Review follow-up (6fbb7c1):** A previously read alternate whitespace
view now returned the new file 1.45 s after the edit, before the 3 s
cache expiry. A rejected host snapshot now sends both reads through the
fallback without an unhandled rejection. Both regression cases failed on
the prior revision. All 301 git plugin tests, typecheck and type-aware
lint passed. With the 200 ms RTT proxy, the updated branch made 61 host
snapshots and 22 client status/files refetches in one minute of churn.
All 11 edits reached the panel, averaging 685 ms.

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

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

Diff viewer is empty when an environment's path is a subdirectory of its git repository

1 participant