src/vs/platform/agentHost/node/agentHostSyncOperationHandler.ts
80 LOC · 31 covered · 49 uncovered · 5 ranges · 923 concepts · 2 introducers · 485 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
agentHostSyncOperationProvider.ts ×5
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken } from '../../../base/common/cancellation.js';
import { URI } from '../../../base/common/uri.js';
import { localize } from '../../../nls.js';
import { parseChangesetUri } from '../common/changesetUri.js';
import type { InvokeChangesetOperationParams, InvokeChangesetOperationResult } from '../common/state/protocol/channels-changeset/commands.js';
import { AHP_SESSION_NOT_FOUND, JsonRpcErrorCodes, ProtocolError } from '../common/state/sessionProtocol.js';
import { readSessionGitState, type SessionState } from '../common/state/sessionState.js';
import { ILogService } from '../../log/common/log.js';
import { IChangesetOperationHandler } from '../common/agentHostChangesetOperationService.js';
import { IAgentHostGitService } from '../common/agentHostGitService.js';
export class AgentHostSyncOperationHandler implements IChangesetOperationHandler {
public static readonly OPERATION_SYNC = 'sync';
constructor(
private readonly _getSessionState: (sessionKey: string) => SessionState | undefined,
agentService.ts ×10
private readonly _onSynced: (sessionKey: string) => Promise<void>,
@IAgentHostGitService private readonly _gitService: IAgentHostGitService,
@ILogService private readonly _logService: ILogService,
) { }
async invoke(params: InvokeChangesetOperationParams, token: CancellationToken): Promise<InvokeChangesetOperationResult> {
const parsed = parseChangesetUri(params.channel);
if (!parsed) {
throw new ProtocolError(JsonRpcErrorCodes.InvalidParams, `Not a changeset URI: ${params.channel}`);
}
this._throwIfCancelled(token);
const sessionUri = parsed.sessionUri;
const sessionState = this._getSessionState(sessionUri);
if (!sessionState) {
throw new ProtocolError(AHP_SESSION_NOT_FOUND, `Session not found: ${sessionUri}`);
}
const workingDirectoryStr = sessionState.workingDirectories?.[0];
if (!workingDirectoryStr) {
throw new ProtocolError(JsonRpcErrorCodes.InternalError, `Session has no working directory: ${sessionUri}`);
}
const workingDirectory = URI.parse(workingDirectoryStr);
const gitState = readSessionGitState(sessionState._meta);
const branchName = gitState?.branchName ?? await this._gitService.getCurrentBranch(workingDirectory);
if (!branchName) {
throw new ProtocolError(JsonRpcErrorCodes.InternalError, `Could not determine current branch for ${workingDirectory}`);
}
this._throwIfCancelled(token);
this._logService.info(`[AgentHostSyncOperationHandler] Syncing branch ${branchName} for session ${sessionUri}`);
try {
// Pull
await this._gitService.pull(workingDirectory);
// Push
await this._gitService.push(workingDirectory);
} catch (err) {
this._throwIfCancelled(token);
throw new ProtocolError(JsonRpcErrorCodes.InternalError, `Failed to sync changes: ${err instanceof Error ? err.message : String(err)}`);
}
try {
await this._onSynced(sessionUri);
} catch (err) {
this._logService.warn(`[AgentHostSyncOperationHandler] Post-sync refresh failed for session ${sessionUri}: ${err instanceof Error ? err.message : String(err)}`);
}
return { message: { markdown: localize('agentHost.changeset.sync.synced', "Synced changes.") } };
}
private _throwIfCancelled(token: CancellationToken): void {
if (token.isCancellationRequested) {
throw new ProtocolError(JsonRpcErrorCodes.InternalError, localize('agentHost.changeset.sync.cancelled', "Sync operation was cancelled."));
}
}