diff options
Diffstat (limited to 'packages/cli/src/services/FileCommandLoader.ts')
| -rw-r--r-- | packages/cli/src/services/FileCommandLoader.ts | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/packages/cli/src/services/FileCommandLoader.ts b/packages/cli/src/services/FileCommandLoader.ts index 1b96cb35..994762c1 100644 --- a/packages/cli/src/services/FileCommandLoader.ts +++ b/packages/cli/src/services/FileCommandLoader.ts @@ -15,7 +15,20 @@ import { getUserCommandsDir, } from '@google/gemini-cli-core'; import { ICommandLoader } from './types.js'; -import { CommandKind, SlashCommand } from '../ui/commands/types.js'; +import { + CommandContext, + CommandKind, + SlashCommand, + SubmitPromptActionReturn, +} from '../ui/commands/types.js'; +import { + DefaultArgumentProcessor, + ShorthandArgumentProcessor, +} from './prompt-processors/argumentProcessor.js'; +import { + IPromptProcessor, + SHORTHAND_ARGS_PLACEHOLDER, +} from './prompt-processors/types.js'; /** * Defines the Zod schema for a command definition file. This serves as the @@ -156,16 +169,45 @@ export class FileCommandLoader implements ICommandLoader { .map((segment) => segment.replaceAll(':', '_')) .join(':'); + const processors: IPromptProcessor[] = []; + + // The presence of '{{args}}' is the switch that determines the behavior. + if (validDef.prompt.includes(SHORTHAND_ARGS_PLACEHOLDER)) { + processors.push(new ShorthandArgumentProcessor()); + } else { + processors.push(new DefaultArgumentProcessor()); + } + return { name: commandName, description: validDef.description || `Custom command from ${path.basename(filePath)}`, kind: CommandKind.FILE, - action: async () => ({ - type: 'submit_prompt', - content: validDef.prompt, - }), + action: async ( + context: CommandContext, + _args: string, + ): Promise<SubmitPromptActionReturn> => { + if (!context.invocation) { + console.error( + `[FileCommandLoader] Critical error: Command '${commandName}' was executed without invocation context.`, + ); + return { + type: 'submit_prompt', + content: validDef.prompt, // Fallback to unprocessed prompt + }; + } + + let processedPrompt = validDef.prompt; + for (const processor of processors) { + processedPrompt = await processor.process(processedPrompt, context); + } + + return { + type: 'submit_prompt', + content: processedPrompt, + }; + }, }; } } |
