mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-08-09 00:16:57 -07:00
refactor(cli): use standardized hydrateString for custom command prompts
This replaces the manual regex for ${extensionPath} with the standardized
hydrateString utility, automatically enabling support for other variables
like ${workspacePath} and ${/} in custom extension commands.
Added a test case to verify ${workspacePath} hydration.
This commit is contained in:
@@ -33,6 +33,7 @@ import {
|
||||
} from './prompt-processors/shellProcessor.js';
|
||||
import { AtFileProcessor } from './prompt-processors/atFileProcessor.js';
|
||||
import { sanitizeForDisplay } from '../ui/utils/textUtils.js';
|
||||
import { hydrateString } from '../config/extensions/variables.js';
|
||||
|
||||
interface CommandDirectory {
|
||||
path: string;
|
||||
@@ -239,13 +240,13 @@ export class FileCommandLoader implements ICommandLoader {
|
||||
|
||||
const validDef = validationResult.data;
|
||||
|
||||
// Hydrate extensionPath if this is an extension command
|
||||
if (extensionPath) {
|
||||
validDef.prompt = validDef.prompt.replace(
|
||||
/\$\{extensionPath\}/g,
|
||||
() => extensionPath,
|
||||
);
|
||||
}
|
||||
// Hydrate variables in the prompt
|
||||
validDef.prompt = hydrateString(validDef.prompt, {
|
||||
extensionPath,
|
||||
workspacePath: this.projectRoot,
|
||||
'/': path.sep,
|
||||
pathSeparator: path.sep,
|
||||
});
|
||||
|
||||
const relativePathWithExt = path.relative(baseDir, filePath);
|
||||
const relativePath = relativePathWithExt.substring(
|
||||
|
||||
Reference in New Issue
Block a user