mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 19:44:30 -07:00
Support @ suggestions for subagenets (#16201)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import type { Config, FileSearch } from '@google/gemini-cli-core';
|
||||
import { FileSearchFactory, escapePath } from '@google/gemini-cli-core';
|
||||
import type { Suggestion } from '../components/SuggestionsDisplay.js';
|
||||
import { MAX_SUGGESTIONS_TO_SHOW } from '../components/SuggestionsDisplay.js';
|
||||
import { CommandKind } from '../commands/types.js';
|
||||
import { AsyncFzf } from 'fzf';
|
||||
|
||||
export enum AtCompletionStatus {
|
||||
@@ -127,6 +128,18 @@ function buildResourceCandidates(
|
||||
return resources;
|
||||
}
|
||||
|
||||
function buildAgentCandidates(config?: Config): Suggestion[] {
|
||||
const registry = config?.getAgentRegistry?.();
|
||||
if (!registry) {
|
||||
return [];
|
||||
}
|
||||
return registry.getAllDefinitions().map((def) => ({
|
||||
label: def.name,
|
||||
value: def.name,
|
||||
commandKind: CommandKind.AGENT,
|
||||
}));
|
||||
}
|
||||
|
||||
async function searchResourceCandidates(
|
||||
pattern: string,
|
||||
candidates: ResourceSuggestionCandidate[],
|
||||
@@ -153,6 +166,26 @@ async function searchResourceCandidates(
|
||||
);
|
||||
}
|
||||
|
||||
async function searchAgentCandidates(
|
||||
pattern: string,
|
||||
candidates: Suggestion[],
|
||||
): Promise<Suggestion[]> {
|
||||
if (candidates.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const normalizedPattern = pattern.toLowerCase();
|
||||
if (!normalizedPattern) {
|
||||
return candidates.slice(0, MAX_SUGGESTIONS_TO_SHOW);
|
||||
}
|
||||
const fzf = new AsyncFzf(candidates, {
|
||||
selector: (s: Suggestion) => s.label,
|
||||
});
|
||||
const results = await fzf.find(normalizedPattern, {
|
||||
limit: MAX_SUGGESTIONS_TO_SHOW,
|
||||
});
|
||||
return results.map((r: { item: Suggestion }) => r.item);
|
||||
}
|
||||
|
||||
export function useAtCompletion(props: UseAtCompletionProps): void {
|
||||
const {
|
||||
enabled,
|
||||
@@ -283,7 +316,14 @@ export function useAtCompletion(props: UseAtCompletionProps): void {
|
||||
value: suggestion.value.replace(/^@/, ''),
|
||||
}));
|
||||
|
||||
const agentCandidates = buildAgentCandidates(config);
|
||||
const agentSuggestions = await searchAgentCandidates(
|
||||
state.pattern ?? '',
|
||||
agentCandidates,
|
||||
);
|
||||
|
||||
const combinedSuggestions = [
|
||||
...agentSuggestions,
|
||||
...fileSuggestions,
|
||||
...resourceSuggestions,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user