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:
Jerop Kipruto
2026-03-17 11:43:46 -04:00
parent 39361bce1f
commit 5e22ebe30e
2 changed files with 66 additions and 7 deletions
@@ -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(