-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add firebase init ai-tools command. #8807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @taeold, 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 Firebase CLI by adding a new ai-tools
initialization command. This feature streamlines the process of integrating Firebase projects with popular AI coding assistants, providing them with rich, structured context about the project's Firebase setup, CLI commands, and best practices. The goal is to empower developers to leverage AI more effectively within their Firebase workflows.
Highlights
- New
firebase init ai-tools
Command: I've introduced a new interactive command,firebase init ai-tools
, which allows users to configure their Firebase projects for various AI coding assistants. This command is now available as an option when runningfirebase init
. - AI Tool Integration: The new command supports configuring three specific AI tools: Cursor, Gemini CLI, and Firebase Studio. For each selected tool, it generates tool-specific configuration files and AI context files within the project directory (e.g.,
.cursor/
,.gemini/
,.idx/
). - Context Generation for AI Assistants: The core functionality involves generating comprehensive Markdown-based context files for AI assistants. These files include general Firebase CLI context (
FIREBASE.md
) and detailed Firebase Functions context (FIREBASE_FUNCTIONS.md
), tailored to each AI tool's preferred format (e.g., file references for Cursor, appended content for Gemini/Studio). The context also includes specific guidelines and a persona for Firebase Studio. - Feature Optimization: Users can optionally choose to optimize the generated AI context based on the Firebase features already enabled in their project (e.g., Functions, Firestore, Hosting). This ensures the AI assistant receives more relevant information, potentially improving its performance and accuracy.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new init
feature for configuring AI agents. The implementation looks good, with new prompt files for context and logic to generate tool-specific configurations.
However, there is a critical issue that prevents the feature from working: the new agents
feature is not registered in the featuresList
in src/init/index.ts
. This will cause firebase init agents
to fail. This file must be updated to include the new feature.
I've also identified a high-severity bug in generateFirebaseContext
that duplicates content for the Firebase Studio configuration, and a medium-severity issue in one of the prompt files. Please see the detailed comments.
Addressing these issues will make this a great addition.
src/init/features/agents.ts
Outdated
function generateFirebaseContext(enabledFeatures: string[], tool: string): string { | ||
// Read base Firebase context from prompts directory | ||
const promptsDir = path.join(__dirname, "../../../prompts"); | ||
let context = fs.readFileSync(path.join(promptsDir, "FIREBASE.md"), "utf8"); | ||
|
||
// Add product-specific contexts based on enabled features | ||
if (enabledFeatures.includes("functions")) { | ||
const functionsContext = fs.readFileSync(path.join(promptsDir, "FIREBASE_FUNCTIONS.md"), "utf8"); | ||
if (tool === "cursor") { | ||
// For Cursor, reference the separate file | ||
context += "\n\n@file ./FIREBASE_FUNCTIONS.md"; | ||
} else { | ||
// For Gemini, append the content | ||
context += "\n\n# Firebase Functions Context\n\n" + functionsContext; | ||
} | ||
} | ||
|
||
// Add headers based on tool type | ||
if (tool === "cursor") { | ||
const header = readTemplateSync("init/agents/cursor-rules-header.txt"); | ||
context = header + "\n\n" + context; | ||
} else if (tool === "studio") { | ||
const header = readTemplateSync("init/agents/studio-airules-header.md"); | ||
// For Studio, integrate the Firebase context into the project context section | ||
const studioContent = header + "\n\nThis is a Firebase project with the following structure and conventions:\n\n" + context; | ||
|
||
// Add Functions-specific guidance if enabled | ||
if (enabledFeatures.includes("functions")) { | ||
const functionsContext = fs.readFileSync(path.join(promptsDir, "FIREBASE_FUNCTIONS.md"), "utf8"); | ||
return studioContent + "\n\n## Firebase Functions Guidelines\n\n" + functionsContext; | ||
} | ||
|
||
return studioContent; | ||
} | ||
|
||
return context; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has a logic bug that causes the Firebase Functions context to be duplicated in the generated file for Firebase Studio. It also reads the FIREBASE_FUNCTIONS.md
file multiple times unnecessarily.
The current logic appends the functions context to the main context
variable for any tool that isn't 'cursor'. Then, for 'studio', it uses this already-extended context and appends the functions context again.
I suggest refactoring this function to simplify the logic, fix the duplication bug, and improve efficiency by reading the file only once. The refactored version below clearly separates the logic for each tool.
function generateFirebaseContext(enabledFeatures: string[], tool: string): string { | |
// Read base Firebase context from prompts directory | |
const promptsDir = path.join(__dirname, "../../../prompts"); | |
let context = fs.readFileSync(path.join(promptsDir, "FIREBASE.md"), "utf8"); | |
// Add product-specific contexts based on enabled features | |
if (enabledFeatures.includes("functions")) { | |
const functionsContext = fs.readFileSync(path.join(promptsDir, "FIREBASE_FUNCTIONS.md"), "utf8"); | |
if (tool === "cursor") { | |
// For Cursor, reference the separate file | |
context += "\n\n@file ./FIREBASE_FUNCTIONS.md"; | |
} else { | |
// For Gemini, append the content | |
context += "\n\n# Firebase Functions Context\n\n" + functionsContext; | |
} | |
} | |
// Add headers based on tool type | |
if (tool === "cursor") { | |
const header = readTemplateSync("init/agents/cursor-rules-header.txt"); | |
context = header + "\n\n" + context; | |
} else if (tool === "studio") { | |
const header = readTemplateSync("init/agents/studio-airules-header.md"); | |
// For Studio, integrate the Firebase context into the project context section | |
const studioContent = header + "\n\nThis is a Firebase project with the following structure and conventions:\n\n" + context; | |
// Add Functions-specific guidance if enabled | |
if (enabledFeatures.includes("functions")) { | |
const functionsContext = fs.readFileSync(path.join(promptsDir, "FIREBASE_FUNCTIONS.md"), "utf8"); | |
return studioContent + "\n\n## Firebase Functions Guidelines\n\n" + functionsContext; | |
} | |
return studioContent; | |
} | |
return context; | |
} | |
function generateFirebaseContext(enabledFeatures: string[], tool: string): string {\n // Read base Firebase context from prompts directory\n const promptsDir = path.join(__dirname, \"../../../prompts\");\n const baseContext = fs.readFileSync(path.join(promptsDir, \"FIREBASE.md\"), \"utf8\");\n\n const functionsEnabled = enabledFeatures.includes(\"functions\");\n const functionsContext = functionsEnabled\n ? fs.readFileSync(path.join(promptsDir, \"FIREBASE_FUNCTIONS.md\"), \"utf8\")\n : \"\";\n\n if (tool === \"cursor\") {\n const header = readTemplateSync(\"init/agents/cursor-rules-header.txt\");\n let context = baseContext;\n if (functionsEnabled) {\n context += \"\\n\\n@file ./FIREBASE_FUNCTIONS.md\";\n }\n return header + \"\\n\\n\" + context;\n } else if (tool === \"studio\") {\n const header = readTemplateSync(\"init/agents/studio-airules-header.md\");\n let studioContent =\n header +\n \"\\n\\nThis is a Firebase project with the following structure and conventions:\\n\\n\" +\n baseContext;\n if (functionsEnabled) {\n studioContent += \"\\n\\n## Firebase Functions Guidelines\\n\\n\" + functionsContext;\n }\n return studioContent;\n }\n\n // Default behavior for other tools like Gemini: append content.\n let context = baseContext;\n if (functionsEnabled) {\n context += \"\\n\\n# Firebase Functions Context\\n\\n\" + functionsContext;\n }\n return context;\n} |
|
||
// v1 imports for Analytics and basic Auth only | ||
import * as functionsV1 from 'firebase-functions/v1'; | ||
import {logger} from 'firebase-functions'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds a new init feature to configure AI coding assistants with Firebase context and MCP server integration. Supported tools: - Cursor: MCP server config + rules files with Firebase context - Gemini CLI: Extension config + combined Firebase context - Firebase Studio: AI rules file with structured Firebase guidance Features: - Multi-select tool configuration - Optional Firebase feature optimization - Modular architecture for easy extension - Single source of truth for prompts in /prompts directory - Clean separation of tool-specific logic Usage: firebase init ai-tools
Remove hyphens from all ai-tools references for consistency: - Command: firebase init aitools (was ai-tools) - File/directory names: aitools.ts, aitools/ (was ai-tools.ts, ai-tools/) - Template paths: init/aitools/ (was init/ai-tools/) - All imports and references updated accordingly
No description provided.