summaryrefslogtreecommitdiff
path: root/packages/cli/src/services/FileCommandLoader.ts
diff options
context:
space:
mode:
authorAbhi <[email protected]>2025-07-23 16:11:23 -0400
committerGitHub <[email protected]>2025-07-23 20:11:23 +0000
commitbbe95f1eaa8f5351c58e0866ba938415db7891e4 (patch)
tree045bd725f24d5b197b5cebaad3a4074c14a99ba1 /packages/cli/src/services/FileCommandLoader.ts
parent2d1eafae95b7a140ac42ea5899f2f4ff6bca80ae (diff)
feat(commands): Implement argument handling for custom commands via a prompt pipeline (#4702)
Diffstat (limited to 'packages/cli/src/services/FileCommandLoader.ts')
-rw-r--r--packages/cli/src/services/FileCommandLoader.ts52
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,
+ };
+ },
};
}
}