feat(cli): add support for the ${extensionPath} variable in extension TOML commands#22681
Conversation
This allows extension commands to dynamically reference and read resources or templates bundled within their specific extension folder, avoiding the need to hardcode absolute paths.
…command
Replaces legacy ~/.gemini/extensions/conductor paths with the dynamic ${extensionPath} variable to ensure built-in and user-installed versions can resolve their internal templates correctly.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the CLI's extension system by enabling extensions to reliably reference their internal resources, regardless of their installation location. It introduces a new Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable ${extensionPath} variable for extension commands, which significantly improves their portability. The overall implementation is solid, and the updates to the Conductor extension and the new unit tests are great additions. However, I've identified one high-severity security issue in the string replacement logic. The current approach can misinterpret special characters (like $) in file paths, potentially leading to incorrect command generation and security risks. I've provided a code suggestion to resolve this by ensuring the path is treated as a literal string during substitution, aligning with best practices for path sanitization.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
This PR enables portability for custom commands defined within extensions by introducing a new
${extensionPath}variable, and immediately applies this feature to fix a critical path resolution bug in the built-in Conductor extension.Previously, extension commands had no reliable way to reference files or assets bundled within their own directory (e.g., the
templatesfolder in Conductor) without hardcoding absolute paths or relying on fragile assumptions about where the extension was installed.By injecting the absolute extension path dynamically at load time, extensions can now reliably bundle and access their own resources regardless of whether they are user-installed or built-in to the CLI bundle.
Details
Commit 1: Core Framework Support
FileCommandLoader.tsto automatically detect and replace${extensionPath}instances in parsed TOMLpromptstrings.Commit 2: Conductor Fix
setup.tomlcommand away from hardcoded paths by replacing them with${extensionPath}/templates/...to copy code style guides and the workflow template.How to Validate
1. Validate the Core Feature (Unit Tests)
Run the updated unit tests for the
FileCommandLoaderto ensure the injection logic is sound:npm run test --workspace @google/gemini-cli -- src/services/FileCommandLoader.test.ts2. Validate the Conductor Fix (Manual)
feat/extension-path-injectionbranch checked out./conductor:setup.Allow execution of: cp ...).cpcommand in the confirmation dialog. The source path should now correctly point to the absolute path of your current extension build directory rather than the hardcoded~/.gemini/extensions/conductor/...path.Pre-Merge Checklist
Fixes #22722