Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/vs/platform/agentHost/node/agentHostChangesetCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from '../common/changesetUri.js';
import { ChangesetStatus } from '../common/state/sessionState.js';
import { IAgentConfigurationService } from './agentConfigurationService.js';
import { ChangesetFileMonitorCoordinator } from './agentHostChangesetFileMonitorCoordinator.js';
import { IAgentHostFileMonitorService } from './agentHostFileMonitorService.js';
import { IAgentHostGitService } from './agentHostGitService.js';
import { AgentHostStateManager } from './agentHostStateManager.js';
import { ILogService } from '../../log/common/log.js';
import {
buildCatalogueFromLiveState,
buildCatalogueFromPersistedDiffs,
Expand Down Expand Up @@ -79,13 +83,18 @@ export class ChangesetSessionCoordinator extends Disposable {
* pure waste).
*/
private readonly _subscribedTurns = new Map<string, Set<string>>();
private readonly _changesetFileMonitor: ChangesetFileMonitorCoordinator;

constructor(
private readonly _stateManager: AgentHostStateManager,
private readonly _changesets: IAgentHostChangesetService,
private readonly _configurationService: IAgentConfigurationService,
fileMonitorService: IAgentHostFileMonitorService,
gitService: IAgentHostGitService,
Comment thread
DonJayamanne marked this conversation as resolved.
logService: ILogService,
) {
super();
this._changesetFileMonitor = this._register(new ChangesetFileMonitorCoordinator(this._stateManager, this._changesets, this._configurationService, fileMonitorService, gitService, logService));
this._changesets.setTurnSubscriberProbe((session, turnId) => this.hasTurnSubscribers(session, turnId));
}

Expand Down Expand Up @@ -134,6 +143,7 @@ export class ChangesetSessionCoordinator extends Disposable {
// drain the deferred refresh. Idempotent — the per-session
// sequencer collapses overlapping computes.
this._drainPendingRefresh(sessionStr);
this._changesetFileMonitor.onSessionRestored(sessionStr);
}

/**
Expand All @@ -143,6 +153,7 @@ export class ChangesetSessionCoordinator extends Disposable {
*/
onSessionMaterialized(sessionStr: string): void {
this._drainPendingRefresh(sessionStr);
this._changesetFileMonitor.onSessionMaterialized(sessionStr);
}

/**
Expand All @@ -152,6 +163,11 @@ export class ChangesetSessionCoordinator extends Disposable {
onSessionDisposed(sessionStr: string): void {
this._pendingUncommittedRefreshes.delete(sessionStr);
this._subscribedTurns.delete(sessionStr);
this._changesetFileMonitor.onSessionDisposed(sessionStr);
}

onSessionTurnActiveChanged(sessionStr: string, active: boolean): void {
this._changesetFileMonitor.onSessionTurnActiveChanged(sessionStr, active);
}

// ---- Subscription hooks -------------------------------------------------
Expand All @@ -170,13 +186,15 @@ export class ChangesetSessionCoordinator extends Disposable {
const parsed = parseChangesetUri(resourceStr);
if (parsed?.kind === ChangesetKind.Uncommitted) {
this._triggerUncommittedRefresh(parsed.sessionUri);
this._changesetFileMonitor.trackSessionChanges(resourceStr, parsed.sessionUri);
return;
}
if (parsed?.kind === ChangesetKind.Session) {
// Session-changeset compute uses git when a working dir is
// available and falls back to the SDK edit-tracker otherwise,
// so it doesn't need the same deferral as uncommitted.
this._changesets.refreshSessionChangeset(parsed.sessionUri);
this._changesetFileMonitor.trackSessionChanges(resourceStr, parsed.sessionUri);
return;
}
if (parsed?.kind === ChangesetKind.Turn && parsed.turnId !== undefined) {
Expand All @@ -202,6 +220,7 @@ export class ChangesetSessionCoordinator extends Disposable {
// editing files manually in the working tree.
this._triggerUncommittedRefresh(resourceStr);
this._changesets.refreshSessionChangeset(resourceStr);
this._changesetFileMonitor.trackSessionChanges(resourceStr, resourceStr);
}
}

Expand All @@ -211,9 +230,15 @@ export class ChangesetSessionCoordinator extends Disposable {
* subscribed anymore, there's no point firing it on materialize.
*/
onLastSubscriber(resource: URI): void {
const parsed = parseChangesetUri(resource.toString());
const resourceStr = resource.toString();
const parsed = parseChangesetUri(resourceStr);
if (parsed?.kind === ChangesetKind.Uncommitted) {
this._pendingUncommittedRefreshes.delete(parsed.sessionUri);
this._changesetFileMonitor.untrackSessionChanges(resourceStr);
return;
}
if (parsed?.kind === ChangesetKind.Session) {
this._changesetFileMonitor.untrackSessionChanges(resourceStr);
return;
}
if (parsed?.kind === ChangesetKind.Turn && parsed.turnId !== undefined) {
Expand All @@ -225,6 +250,9 @@ export class ChangesetSessionCoordinator extends Disposable {
}
}
}
if (!parsed) {
this._changesetFileMonitor.untrackSessionChanges(resourceStr);
}
}

/**
Expand Down
Loading
Loading