feat: rename sidebar-agent-list to sidebar-workspace-list and emit workspace updates on agent removal

This commit is contained in:
Mohamed Boudra
2026-03-04 10:01:11 +07:00
parent e9b57a5ac6
commit bf1cded8a1
4 changed files with 232 additions and 25 deletions
+24
View File
@@ -4544,10 +4544,12 @@ export class Session {
}
const removedAgents = new Set<string>()
const affectedWorkspaceCwds = new Set<string>([targetPath])
const agents = this.agentManager.listAgents()
for (const agent of agents) {
if (this.isPathWithinRoot(targetPath, agent.cwd)) {
removedAgents.add(agent.id)
affectedWorkspaceCwds.add(agent.cwd)
try {
await this.agentManager.closeAgent(agent.id)
} catch {
@@ -4565,6 +4567,7 @@ export class Session {
for (const record of registryRecords) {
if (this.isPathWithinRoot(targetPath, record.cwd)) {
removedAgents.add(record.id)
affectedWorkspaceCwds.add(record.cwd)
try {
await this.agentStorage.remove(record.id)
} catch {
@@ -4591,6 +4594,8 @@ export class Session {
})
}
await this.emitWorkspaceUpdatesForCwds(affectedWorkspaceCwds)
return Array.from(removedAgents)
}
@@ -5671,6 +5676,25 @@ export class Session {
})
}
private async emitWorkspaceUpdatesForCwds(cwds: Iterable<string>): Promise<void> {
if (!this.workspaceUpdatesSubscription) {
return
}
const uniqueWorkspaceCwds = new Set<string>()
for (const cwd of cwds) {
const normalized = this.normalizeWorkspaceId(cwd)
if (!normalized) {
continue
}
uniqueWorkspaceCwds.add(normalized)
}
for (const workspaceCwd of uniqueWorkspaceCwds) {
await this.emitWorkspaceUpdateForCwd(workspaceCwd)
}
}
private async handleFetchAgents(
request: Extract<SessionInboundMessage, { type: 'fetch_agents_request' }>
): Promise<void> {
@@ -264,4 +264,29 @@ describe('workspace aggregation', () => {
id: '/tmp/repo',
})
})
test('workspace update fanout for multiple cwd values is deduplicated', async () => {
const session = createSessionForWorkspaceTests() as any
session.workspaceUpdatesSubscription = {
subscriptionId: 'sub-dedupe',
filter: undefined,
isBootstrapping: false,
pendingUpdatesByWorkspaceId: new Map(),
}
const emitWorkspaceUpdateForCwd = vi.fn(async () => {})
session.emitWorkspaceUpdateForCwd = emitWorkspaceUpdateForCwd
await session.emitWorkspaceUpdatesForCwds([
'/tmp/repo',
'/tmp/repo/',
' /tmp/repo ',
'/tmp/repo/sub',
'/tmp/repo/sub/',
])
expect(emitWorkspaceUpdateForCwd).toHaveBeenCalledTimes(2)
expect(emitWorkspaceUpdateForCwd).toHaveBeenNthCalledWith(1, '/tmp/repo')
expect(emitWorkspaceUpdateForCwd).toHaveBeenNthCalledWith(2, '/tmp/repo/sub')
})
})