Update active session while it is in progress

This commit is contained in:
Ladislau Szomoru
2026-02-12 13:24:55 +01:00
parent 71794ff7ce
commit cfb37c8a37

View File

@@ -132,6 +132,11 @@ export class ActiveAgentSessionService extends Disposable implements IActiveAgen
}
}
}));
// Update active session when the agent sessions model changes (e.g., metadata updates with worktree/repository info)
this._register(this.agentSessionsService.model.onDidChangeSessions(() => {
this.refreshActiveSessionFromModel();
}));
}
private registerChatBarWidgetTracking(): void {
@@ -206,6 +211,29 @@ export class ActiveAgentSessionService extends Disposable implements IActiveAgen
}
}
private refreshActiveSessionFromModel(): void {
const currentActive = this._activeSession.get();
if (!currentActive) {
return;
}
const agentSession = this.agentSessionsService.model.getSession(currentActive.resource);
if (!agentSession) {
return;
}
const [repository, worktree] = this.getRepositoryFromMetadata(agentSession.metadata);
if (currentActive.repository?.toString() !== repository?.toString() || currentActive.worktree?.toString() !== worktree?.toString()) {
const activeSessionItem: IActiveAgentSessionItem = {
...agentSession,
repository,
worktree,
};
this.logService.info(`[ActiveAgentSessionService] Active session updated from model: ${currentActive.resource.toString()}, repository: ${repository?.toString() ?? 'none'}, worktree: ${worktree?.toString() ?? 'none'}`);
this._activeSession.set(activeSessionItem, undefined);
}
}
private getRepositoryFromMetadata(metadata: { readonly [key: string]: unknown } | undefined): [URI | undefined, URI | undefined] {
if (!metadata) {
return [undefined, undefined];