477
}
478
}
480
>
481
>
this._reconcileWatchers(nextWatchRootUris);
482
>
}
483
484
485
public async discover(client: CopilotClient, token: CancellationToken): Promise<readonly DirectoryCustomization[]> {
487
>
method: 'discover',
488
>
workingDirectory: this._workingDirectory.toString(),
489
>
userHome: this._userHome.toString(),
490
>
});
491
>
if (!this._discoveredDirectories) {
492
>
this._discoveredDirectories = await this.getDiscoveredDirectories(client, token);
493
>
}
494
>
495
>
throwIfCancelled(token);
496
>
497
>
const p: AgentsDiscoverRequest = { projectPaths: [this._workingDirectory.fsPath] };
498
>
499
>
try {
500
>
const [agents, rules, skills, hooks] = await Promise.all([
501
>
this.discoverAgents(p, client, token),
502
>
this.discoverRules(p, client, token),
503
>
this.discoverSkills(p, client, token),
504
>
this.discoverHooks(token),
505
>
this._updateWatchers(this._discoveredDirectories, token)
506
>
]);
507
>
throwIfCancelled(token);
508
>
const result: DirectoryCustomization[] = [];
509
>
await this.toDirectoryCustomizations(CustomizationType.Agent, agents, this._discoveredDirectories, result);
510
>
await this.toDirectoryCustomizations(CustomizationType.Rule, rules, this._discoveredDirectories, result);
511
>
await this.toDirectoryCustomizations(CustomizationType.Skill, skills, this._discoveredDirectories, result);
512
>
await this.toDirectoryCustomizations(CustomizationType.Hook, hooks, this._discoveredDirectories, result);
513
>
const sortedResult = result.sort(compareDirectoryCustomization);
514
>
await this.writeCustomizationDiscoveryDebugLog({
515
>
method: 'discover',
516
>
result: sortedResult.map(customization => ({
517
>
contents: customization.contents,
518
>
uri: customization.uri,
519
>
children: (customization.children ?? []).map(child => ({ type: child.type, uri: child.uri, name: child.name })),
520
>
})),
521
>
});
522
>
return sortedResult;
523
>
} catch (err) {
524
this._logService.error(`[SessionCustomizationDiscovery] Error during discovery: ${err instanceof Error ? err.message : String(err)}`);
525
return [];
526
}
528
529
private async discoverAgents(discoveryRequest: AgentsDiscoverRequest, client: CopilotClient, token: CancellationToken): Promise<AgentCustomization[]> {
531
>
532
>
const agentDiscovery = await raceCancellationError(client.rpc.agents.discover(discoveryRequest), token);
533
>
for (const agent of agentDiscovery.agents) {
534
if (agent.path) {
535
const uri = this._pathToUri(agent.path);