Skip to content

Adopt AHP 0.7.0 workingDirectories + primaryWorkingDirectory in agent host#326847

Merged
sandy081 merged 10 commits into
mainfrom
agents/multiroot-workspaces-support-agents
Jul 22, 2026
Merged

Adopt AHP 0.7.0 workingDirectories + primaryWorkingDirectory in agent host#326847
sandy081 merged 10 commits into
mainfrom
agents/multiroot-workspaces-support-agents

Conversation

@sandy081

Copy link
Copy Markdown
Member

Summary

Syncs the generated agent host protocol copy to spec version 0.6.0 (agent-host-protocol @ 11f1a65e), which renames the singular workingDirectory on session/chat state to a workingDirectories array in preparation for multiroot session support.

This is milestone 1 of multiroot support: a pure, behaviour-preserving property adoption. Sessions continue to use a single working directory — no user-visible change.

What changed

  • Generated protocol (14 files): re-synced to spec 0.6.0 via scripts/sync-agent-host-protocol.ts. The singular workingDirectory is replaced by workingDirectories?: URI[] on the session/chat state and summary types. (.ahp-version11f1a65e.)
  • Consumers (39 files): mechanical migration of the renamed property:
    • reads that consume a single directory → x.workingDirectories?.[0]
    • field-copy / passthrough sites → whole-array passthrough (x.workingDirectories)
    • object-literal writes from a single URI → dir ? [dir] : undefined (or [dir] in tests)

Explicitly not in this PR

No multiroot client support is added here — no capability advertising (multipleWorkingDirectories), no workingDirectorySet/workingDirectoryRemoved state actions, no multi-folder workspaces, and no UI. Those land in a follow-up milestone.

Validation

  • tsc --project ./src/tsconfig.json --noEmit — clean
  • npm run valid-layers-check — clean
  • Pre-commit hygiene hook — passed

Note: the singular workingDirectory on the pre-session config commands (ResolveSessionConfigParams, SessionConfigCompletionsParams) is intentionally retained — those resolve config before a session exists and are single-context by design.

Follow-up

Once the spec PR (microsoft/agent-host-protocol#337) merges, repoint .ahp-version/sync source from the spec-branch commit to the merged commit.

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

Sync the generated agent host protocol copy to spec version 0.6.0
(agent-host-protocol @ 11f1a65e), which renames the singular
`workingDirectory` on session/chat state to a `workingDirectories`
array in preparation for multiroot session support.

This change is a pure, behaviour-preserving property adoption across all
consumers: sessions continue to use a single working directory. Reads of
a single directory now use `workingDirectories?.[0]`, field-copy sites
pass the array through unchanged, and writes from a single URI produce a
one-element array. No multiroot client support is added here (no
capability advertising, state actions, multi-folder workspaces, or UI);
those land in a follow-up milestone.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 21, 2026 17:24
…spaces-support-agents

# Conflicts:
#	src/vs/platform/agentHost/test/node/protocol/agentHostE2ETestHelpers.ts

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.

Pull request overview

Adopts AHP 0.6.0’s workingDirectories array while retaining single-directory behavior.

Changes:

  • Syncs generated protocol definitions to 11f1a65e.
  • Migrates host consumers to read or emit the first array entry.
  • Updates affected fixtures and tests.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Updates mock session summaries.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionListStore.ts Migrates session-list directory handling.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionListController.ts Reads the primary directory.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Migrates resolved-directory lookup.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostGenericConfigChips.ts Migrates chip directory lookup.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts Supplies the primary directory.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatInputPicker.ts Migrates picker directory lookup.
src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts Updates remote-provider fixtures.
src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts Updates local-provider fixtures.
src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts Migrates provider metadata mapping.
src/vs/platform/agentHost/test/node/sessionPermissions.test.ts Updates permission fixtures.
src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts Updates protocol-handler mocks.
src/vs/platform/agentHost/test/node/protocol/agentHostE2ETestHelpers.ts Updates protocol assertions.
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts Updates side-effect fixtures.
src/vs/platform/agentHost/test/node/agentService.test.ts Updates service fixtures and assertions.
src/vs/platform/agentHost/test/node/agentHostStateManager.test.ts Updates state-manager tests.
src/vs/platform/agentHost/test/node/agentHostPullRequestOperationHandler.test.ts Updates pull-request fixtures.
src/vs/platform/agentHost/test/node/agentHostGitStateService.test.ts Updates Git-state fixtures.
src/vs/platform/agentHost/test/node/agentHostFileCompletionProvider.test.ts Updates completion fixtures.
src/vs/platform/agentHost/test/node/agentHostDiscardChangesOperationHandler.test.ts Updates discard-operation fixtures.
src/vs/platform/agentHost/test/node/agentHostCommitOperationHandler.test.ts Updates commit-operation fixtures.
src/vs/platform/agentHost/test/node/agentHostChangesetService.test.ts Updates changeset fixtures.
src/vs/platform/agentHost/test/node/agentHostChangesetCoordinator.test.ts Updates coordinator fixtures.
src/vs/platform/agentHost/test/node/agentConfigurationService.test.ts Updates configuration fixtures.
src/vs/platform/agentHost/node/protocolServerHandler.ts Reads the primary create-session directory.
src/vs/platform/agentHost/node/localCommands/bangLocalCommand.ts Migrates terminal working directory.
src/vs/platform/agentHost/node/agentService.ts Migrates host state producers and consumers.
src/vs/platform/agentHost/node/agentHostSyncOperationHandler.ts Migrates sync directory lookup.
src/vs/platform/agentHost/node/agentHostStateManager.ts Migrates summary and state propagation.
src/vs/platform/agentHost/node/agentHostReviewService.ts Migrates review directory lookup.
src/vs/platform/agentHost/node/agentHostPullRequestOperationHandler.ts Migrates pull-request operations.
src/vs/platform/agentHost/node/agentHostGitStateService.ts Migrates Git-state lookup.
src/vs/platform/agentHost/node/agentHostFileCompletionProvider.ts Migrates completion lookup.
src/vs/platform/agentHost/node/agentHostDiscardChangesOperationHandler.ts Migrates discard operations.
src/vs/platform/agentHost/node/agentHostCommitOperationHandler.ts Migrates commit operations.
src/vs/platform/agentHost/node/agentHostChangesetService.ts Migrates changeset computations.
src/vs/platform/agentHost/node/agentConfigurationService.ts Migrates effective-directory resolution.
src/vs/platform/agentHost/common/state/sessionState.ts Migrates state conversion and merging.
src/vs/platform/agentHost/common/state/protocol/version/registry.ts Registers 0.6.0 actions.
src/vs/platform/agentHost/common/state/protocol/common/commands.ts Syncs generated command metadata.
src/vs/platform/agentHost/common/state/protocol/common/actions.ts Adds generated action types.
src/vs/platform/agentHost/common/state/protocol/channels-session/state.ts Defines session directory arrays.
src/vs/platform/agentHost/common/state/protocol/channels-session/reducer.ts Adds session directory reducers.
src/vs/platform/agentHost/common/state/protocol/channels-session/commands.ts Migrates create-session parameters.
src/vs/platform/agentHost/common/state/protocol/channels-session/actions.ts Defines session directory actions.
src/vs/platform/agentHost/common/state/protocol/channels-root/state.ts Defines multiroot capability types.
src/vs/platform/agentHost/common/state/protocol/channels-chat/state.ts Defines chat directory subsets.
src/vs/platform/agentHost/common/state/protocol/channels-chat/reducer.ts Adds chat directory reducers.
src/vs/platform/agentHost/common/state/protocol/channels-chat/commands.ts Adds initial chat directory subsets.
src/vs/platform/agentHost/common/state/protocol/channels-chat/actions.ts Defines chat directory actions.
src/vs/platform/agentHost/common/state/protocol/action-origin.generated.ts Registers generated action origins.
src/vs/platform/agentHost/common/state/protocol/.ahp-version Pins the synced specification commit.
src/vs/platform/agentHost/browser/remoteAgentHostProtocolClient.ts Migrates remote protocol mapping.

Review details

  • Files reviewed: 53/53 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment thread src/vs/platform/agentHost/node/agentHostStateManager.ts Outdated
Comment thread src/vs/platform/agentHost/common/state/sessionState.ts
- Reject the not-yet-supported multiroot working-directory client actions
  (session|chat/workingDirectorySet|Removed) in the handwritten dispatch path
  so a client cannot mutate the synchronized working-directory set without the
  agent actually reconfiguring its directory access. The protocol declarations
  remain; only the operational dispatch is deferred until multiroot lands.
- Compare workingDirectories by array identity (not just the primary entry) in
  the state manager summary-equality check, matching the immutable reducers and
  SessionSummaryNotifier so secondary-directory changes still dirty the summary.
- Update ISessionWithDefaultChat / mergeSessionWithDefaultChat API docs to
  describe a chat's workingDirectories subset overriding or inheriting the
  session's full set, fixing links to the removed singular members.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
connor4312
connor4312 previously approved these changes Jul 21, 2026
The `sessionAdded notification filters out sessions outside the workspace`
test constructed session summaries with the removed singular `workingDirectory`
field, so the production filter (which now reads `workingDirectories[0]`) saw no
directory and dropped the in-workspace session. Update the two directly-built
summaries to the `workingDirectories` array form.

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

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Base: cc98d9c2 Current: 5e69a705

No screenshot changes.

@sandy081
sandy081 marked this pull request as ready for review July 21, 2026 19:06
sandy081 and others added 2 commits July 21, 2026 14:39
The createSession dispatch handler now reads the working directory from the
renamed `CreateSessionParams.workingDirectories` array (AHP 0.6.0), but several
node integration / e2e test call sites still sent the removed singular
`workingDirectory` field. Since the field is silently ignored, sessions were
created without a working directory and fell back to the default chats folder,
failing the Agent Host E2E workspace/fileOperations/hostFeatures suites across
all providers (wrong cwd cascades into file completions, renames, worktree
resolution, and cd-prefix stripping).

Send `workingDirectories: [dir]` from the shared `createProviderSession` helper
and the remaining direct wire call sites so the requested directory reaches the
session state again. The real VS Code client already sent the array form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandy081
sandy081 enabled auto-merge (squash) July 21, 2026 23:59
@sandy081
sandy081 disabled auto-merge July 22, 2026 00:03

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

AI Review: Two inline findings added.

Comment thread src/vs/platform/agentHost/node/protocolServerHandler.ts
Comment thread src/vs/platform/agentHost/node/protocolServerHandler.ts Outdated
DonJayamanne
DonJayamanne previously approved these changes Jul 22, 2026
Re-sync the generated protocol copy to the multiroot spec at 148c716b (spec
version 0.7.0) and adopt the two follow-up changes:

- Capability flag renamed `MultipleWorkingDirectoriesCapability.immutablePrimary`
  -> `requiresPrimary`, with the new "agent needs one directory designated as
  its primary root" semantics. No consumers referenced the old name.
- New optional `primaryWorkingDirectory` field at both the session level
  (CreateSessionParams / SessionMetadata -> SessionState + SessionSummary) and
  the chat level (CreateChatParams / ChatState + ChatSummary). Mirror it through
  the state<->summary projection layer exactly like `workingDirectories`:
  createSessionState / createChatState / chatSummaryFromState /
  mergeSessionWithDefaultChat, plus the state manager's summary projection,
  field-equality check, SessionSummaryNotifier diff, and markSessionPersisted
  propagation. The generated SessionChatUpdated partial-summary merge is
  field-agnostic, so it carries the new field automatically.

Purely additive optional fields; no client multiroot behavior is added
(consumers still read `workingDirectories[0]` as the single effective root).

Also preserve the VS Code-local `CompletionItem.label` field (added in #326807,
ahead of the spec) which the verbatim re-sync would otherwise drop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address PR review feedback on the multiroot working-directory action gate:

- Instead of silently dropping the four not-yet-supported
  session|chat/workingDirectorySet|Removed client actions (which never echoed
  the origin, leaving the client's optimistic write-ahead action pending until
  reconnect), emit a rejection envelope through the normal reconciliation path.
  Added AgentHostStateManager.rejectClientAction, which emits an ActionEnvelope
  carrying the original ActionOrigin and a rejectionReason without running the
  reducer (no synchronized state change), so the originating client rolls back
  its optimistic action.
- Guard the write-ahead client reconcile (SessionStateSubscription /
  ChatStateSubscription) so a rejected envelope is never applied to confirmed
  state in any branch — this also prevents a broadcast rejection from leaking
  the rejected action into a non-origin client's state.
- Add a table-driven test covering all four action types asserting no dispatch
  and exactly one rejection envelope preserving the original origin.
- Simplify the create-session working-directory read to
  `URI.parse(params.workingDirectories[0])` now the branch proves index 0 exists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
roblourens
roblourens previously approved these changes Jul 22, 2026
@sandy081
sandy081 marked this pull request as draft July 22, 2026 06:00
Re-sync the protocol copy to spec ea279d99 (0.7.0) and adopt the refined
primaryWorkingDirectory design:

- Session has NO primary: `primaryWorkingDirectory` is removed from
  SessionState / SessionSummary. The session is just the equal-peer
  `workingDirectories` set. Dropped all session-level primary handling
  (createSessionState, the SessionSummaryNotifier diff, _toSummary,
  _summaryFieldsEqual, and markSessionPersisted propagation).
- Primary is per-chat, read-only, fixed at chat creation: kept the ChatState
  <-> ChatSummary mirroring (createChatState / chatSummaryFromState) and carry
  the chat's own primary through the session+default-chat composite
  (ISessionWithDefaultChat gains its own primaryWorkingDirectory; the merge no
  longer falls back to a session primary). It is not sent via `session/chatUpdated`
  (the state manager only ever puts status/activity/title in those changes), so
  it never mutates post-creation.
- Inputs `CreateSessionParams.primaryWorkingDirectory` (seeds the default chat's
  primary) and `CreateChatParams.primaryWorkingDirectory` are synced; capability
  `requiresPrimary` unchanged.

Also re-preserve the VS Code-local `CompletionItem.label` field (#326807, ahead
of the spec) that the verbatim re-sync drops.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandy081
sandy081 marked this pull request as ready for review July 22, 2026 14:54
@sandy081 sandy081 changed the title Adopt AHP 0.6.0 workingDirectories property in agent host Adopt AHP 0.7.0 workingDirectories + primaryWorkingDirectory in agent host Jul 22, 2026
@sandy081
sandy081 enabled auto-merge (squash) July 22, 2026 15:02
@sandy081
sandy081 merged commit 53ebd21 into main Jul 22, 2026
29 checks passed
@sandy081
sandy081 deleted the agents/multiroot-workspaces-support-agents branch July 22, 2026 15:19
@vs-code-engineering vs-code-engineering Bot added this to the 1.131.0 milestone Jul 22, 2026
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.

6 participants