Skip to content

Workbench: worktree locations from agent host sessions, a shown-session seam and shared folder picker sections (infra, unused) - #348304

Draft
Sandeep Somavarapu (sandy081) wants to merge 22 commits into
mainfrom
sandy081/agents/editor-window-worktree-locations
Draft

Sandeep Somavarapu (sandy081) wants to merge 22 commits into
mainfrom
sandy081/agents/editor-window-worktree-locations

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Infra for worktree support in the editor window (#348306) and for the chat area's folder picker (#348298). No behavior change: nothing registers or uses these pieces yet. Merge order: this PR first; #348298 and #348306 merge its branch.

Changes

  • Shown-session seam:
    • IChatViewHostService.shownSession, with IChatViewHost.shownSession (optional) and IChatViewHostShownSession { resource, reason: 'open' | 'commit' | 'restore' }: the chat that the host in use shows, and why: the user brought it up (open), a new chat's first request made it (commit), or the host restored it (restore). IChatViewHostOpenOptions gains restore and commit.
    • The Chat view reports it: restore only inside its two restore paths, commit for the session that a new chat's first request makes (commitChatSession opens it with commit: true, and the widget's view model change carries committed), and open for a chat picked in its sessions list or a new chat.
    • A registered host that replaces the Chat view reports its own; one that reports none leaves it undefined.
  • Worktree locations from agent host sessions: AgentHostWorktreeLocationProvider, an IWorkspaceFolderLocationProvider that is not registered here.
    • A folder's locations are the distinct working directories of the local agent host's sessions that are linked checkouts of the folder's git repository, as the editor window decides that a folder belongs to its repository (WorkspaceFolderRepositories), and whose entry in the repository names them back.
    • Where sessions work comes from the Chat view's sessions list and from IAgentHostWorktreeSessionSources, where another session surface (such as a sessions list the Chat view does not show) registers a source. Sources only nominate working directories; the provider alone decides which are locations of the folder.
    • There is no discovery of the repository's worktrees.
  • Shared folder picker labels and sections (services/workspaces/common/folderLocationSections.ts), so that the pickers in chat and in sessions share them: groupFolderLocations (a Folder section, Folders with several, and a Worktrees section, each with the current folder first), and the labels Current, New Worktree, and the detail lines of the folder ("Works in the folder already on this computer") and of New Worktree ("Creates a separate copy for this session", as the Agents window's isolation picker says).
  • readFolderGitCheckout, the reading of a folder's .git that WorkspaceFolderRepositories does, moves to services/workspaces/common/gitFolderCheckout.ts so that chat can use it too. WorkspaceFolderRepositories behaves as before.

Review fixes

How to test

Unit tests:

  • agentHostWorktreeLocations.test.ts: which sessions count, from the sessions list and from registered sources, and which working directories are offered and resolved.
  • chatViewHostService.test.ts and chatViewPane.test.ts: the shown chat follows the host in use, with its reason.
  • folderLocationSections.test.ts: the sections and their order.

Validation (macOS, on ca9b1ea, up to date with main 9bfb9e7):

  • pnpm run typecheck-client: passed
  • pnpm run build-fast --client-only, then ./scripts/test.sh --reporter dot --run <agentHostWorktreeLocations, chatViewHostService, chatViewPane, folderLocationSections, workspaceFolderRepositories, chatWidgetService, chatMoveActions .test.ts>: 87 passing
  • Earlier, before the merge of main: pnpm run valid-layers-check and oxlint on the changed files: passed

Not run: the full unit suite, and a live Code OSS run (the try-out covers the features that use it).

Final sweep

  • Final sweep: merged main 776b518 (25ab514, clean). pnpm run typecheck-client: passed; pnpm run build-fast --client-only, then ./scripts/test.sh --reporter dot --run <changed test files vs main>: 82 passing.

…s locations of the window's folder

A window with a single local folder can now move that folder to the worktrees its local agent host sessions work in, behind the experimental setting chat.editorWindow.enableWorktree (off by default, experiment-controlled).

- AgentHostWorktreeLocationProvider: the locations of a folder are the distinct working directories of the local agent host's sessions (not archived; local chats and extension sessions belong to the folder itself). A working directory counts when it is a linked checkout of the folder's git repository, as the editor window decides that a folder belongs to its repository, and when the repository's entry for it names it back, so a folder that only points into the repository does not inherit the folder's trust. Any such checkout resolves, also before the sessions load, to restore the location the folder was at. There is no discovery of the repository's worktrees.
- It is registered as a built-in provider while the setting is on, not in the Agents window.
- readFolderGitCheckout moves from WorkspaceFolderRepositories to services/workspaces/common, so that both can read a folder's checkout; WorkspaceFolderRepositories is unchanged otherwise.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 14, 2026 03:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The picker snapshots sessions before initial model resolution completes, omitting uncached worktrees until reopened; it should await resolution and test initially unloaded sessions.

1 open issue
What changed in this PR

Adds local agent-host session worktrees to VS Code’s existing folder-location service, laying the groundwork for switching a single-folder editor window between checkouts.

Changes:

  • Registers a worktree location provider behind the default-off experimental chat.editorWindow.enableWorktree setting.
  • Validates repository membership and reverse Git links, including when restoring locations no longer listed by sessions.
  • Extracts shared Git-checkout parsing and adds focused provider tests.
File Description
src/​vs/​workbench/​services/​workspaces/​common/​gitFolderCheckout.ts Extracts checkout parsing and exposes worktree Git-directory metadata.
src/​vs/​workbench/​contrib/​sessions/​browser/​workspaceFolderRepositories.ts Uses the shared parser without changing repository lookup behavior.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHost/​agentHostWorktreeLocations.test.ts Tests session filtering and worktree validation and resolution.
src/​vs/​workbench/​contrib/​chat/​common/​constants.ts Defines the experimental setting identifier.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentSessions.contribution.ts Loads the worktree-location contribution.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostWorktreeLocations.ts Implements the provider, validation, setting, and gated editor-window registration.

Review effort: Balanced

…r picker sections (infra, unused)

Infra for worktree support in the editor window; nothing registers or uses it yet.

- IChatViewHostService.shownSession, with IChatViewHost.shownSession and IChatViewHostShownSession { resource, reason: 'open' | 'restore' }: the chat that the host in use shows, and whether the user brought it up or the host restored it. The Chat view reports it: 'restore' for the chat it restores, 'open' for a chat picked in its sessions list, a new chat, and a new chat that its first request made real. A host that replaces the Chat view reports its own; one that reports none leaves it undefined.
- folderLocationSections.ts: the sections that every picker of a window's folders and their worktrees shows (Folder or Folders, then Worktrees, each with the current folder first), and their labels, so that the pickers share them.
- AgentHostWorktreeLocationProvider is no longer registered here, and the setting moves out with its registration: the feature that uses them registers them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandy081 Sandeep Somavarapu (sandy081) changed the title Editor window: offer the worktrees that agent host sessions work in as locations of the window's folder Workbench: worktree locations from agent host sessions, a shown-session seam and shared folder picker sections (infra, unused) Nov 14, 2026
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
) into sandy081/agents/worktree-picker-groups

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
… folder picker sections

The Folder (or Folders) and Worktrees sections of a composer restricted to a window's folders, their order and their labels (Current, New Worktree) now come from folderLocationSections (#348304), which the Chat view's folder chip shares, rather than from rules of its own. The picker shows the same items as before.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not one that the user loads meanwhile

The Chat view marked every chat it showed while its restore was under way as restored, also a chat that the user loaded meanwhile and that superseded the restore. It now passes the reason with the chat it shows, and reports it only while it sets that chat.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
) into sandy081/agents/editor-window-worktree-follow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
) into sandy081/agents/worktree-picker-groups

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
As the Chat view does since #348304: a chat that the user opens while the chat part restores its tabs is opened, not restored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ectories, and report an explicitly opened chat as opened

Copilot code review fixes:
- AgentHostWorktreeLocationProvider waits for the sessions list to resolve before reading the working directories of its sessions, so the worktrees of sessions that it did not cache are not missing.
- The Chat view reports a chat that the user opens or reveals as opened, also one that it shows already, such as one it restored that the user picks in a sessions list (ChatViewPane.reportOpened, from the Chat view host's openSession and revealIfShowing).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
…ows it

The Chat view host service now reports the shown chat of the host that showed a chat last: the
host that an open, start or reveal goes to (the Chat view for the chats a registered host leaves
to it), or the host that restores or shows a chat on its own. New Chat of every icon variant now
lets a host that replaces the Chat view start the new chat.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
) into sandy081/agents/editor-window-worktree-follow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
) into sandy081/agents/worktree-picker-groups

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The resolution guard can skip waiting when a sibling provider finishes first, causing uncached worktrees to be omitted while the agent host is still loading.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Wait for agent-host providers to finish resolving

src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostWorktreeLocations.ts:70

model.resolved becomes true when any single provider finishes (agentSessionsModel.ts:876–877), not when the initial resolution of all providers completes. If a local-chat provider finishes before the agent host, this guard skips waiting while the host is still loading, so uncached worktrees remain absent from the returned locations. Await the relevant agent-host providers' resolution (or expose and await the model's full initial-resolution promise), and cover a fast sibling provider with a delayed agent-host provider in the test.

1 resolved since last review

Review effort: Balanced

… report first sends and restored opens

- The location provider resolves through real paths (a symlinked primary or worktree keeps its identity), reads the entry's HEAD for the branch or short commit, and no longer drops all locations when one fails to read.
- IChatViewHostShownSession gains reason 'commit' for the chat a first request made; IChatViewHostOpenOptions gains restore to show a session without reporting it as opened.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… reports it as restored

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lso one reported as opened already

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

First-request replacements can still report open or bypass the event, preventing consumers from reliably distinguishing commits from user selections across host-driven and direct-widget model-binding paths.

1 open issue

Review effort: Balanced

Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
- chatViewHostService.ts: restore the reportRestored branch (#348304's
  039d452), lost in an earlier resolution; now identical to #347688 and #348283.
- agentsViewGate.test.ts: take the banner's test, which matches the banner's gate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ugh an extension's commit, and follow symbolic links of worktree folders and .git files

- ChatWidget marks the view model change to the session its first request made; the Chat view reports it as 'commit'.
- IChatViewHostOpenOptions.commit: the extension commit path opens the committed session through the Chat view host as 'commit'.
- The location provider compares the real paths of the repository's worktrees folder and of a worktree's .git file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…h reportShown

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the editor-window worktree support infrastructure.

1 open issue

Review effort: Balanced

…tself, and an open through the Chat view host reports its chat once

- The location provider accepts a candidate only where the folder of the .git file its entry names is the candidate, by real paths, so another folder whose .git links to the same file does not inherit the primary's trust.
- ChatViewPaneHost reports a chat after loading it only where the load reported nothing, such as the chat it shows already.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, and Chat view mocks expose the shown session

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…s a later open supersedes it

The host no longer infers from the shown session whether a load reported its chat: a superseded restore no longer reports its reason after the explicit open that superseded it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…des the Chat view's sessions list

IAgentHostWorktreeSessionSources lets another session layer, such as the editor window's, nominate where its sessions and chats work. AgentHostWorktreeLocationProvider offers the union of the Chat view's sessions and every source, deduplicated, and still accepts only a linked checkout that git names back.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rst request is shown as committed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
… as committed

As the Chat view shows it (#348304 dd8a606), so a follow of where the window's folder is does not take it for a session the user opened.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Nov 14, 2026
getComposerFolderOptions returns live options: a composer created before a feature offers its folders, such as the Chat view's composer during restore, follows that feature's folders and presentation, and the window's folders again once it goes. Also disposes the Chat view host service of #348304's committed-session test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… show below their names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nside it

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…inline, its detail as far below its label

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…pply to their own lists instead

This reverts commits a82a018 and 6aa8ba0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the shared worktree and folder-picker infrastructure changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The folder picker can show duplicate entries when sessions reference the same worktree via real and symlink paths; deduplication by real checkout path and a regression test are needed.

1 open issue

Review effort: Balanced

…e (CCR)

A worktree that sessions work in through a symbolic link and through its real path showed twice in the folder picker. Locations are now deduplicated by their real path, keeping the first.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

2 participants