-
Notifications
You must be signed in to change notification settings - Fork 283
feat: Add AI coding assistant rules command #2128
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
Open
dcodesdev
wants to merge
5
commits into
main
Choose a base branch
from
feat/ai-rules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Shuttle Development Rules | ||
|
|
||
| ## Core Setup | ||
|
|
||
| Always use `#[shuttle_runtime::main]` as your entry point. Can be other frameworks too, you can use the Shuttle MCP - search docs tool to find the correct code for your framework. | ||
|
|
||
| ```rust | ||
| #[shuttle_runtime::main] | ||
| async fn main() -> ShuttleAxum { | ||
| let router = Router::new().route("/", get(hello)); | ||
| Ok(router.into()) | ||
| } | ||
| ``` | ||
|
|
||
| ## Databases | ||
|
|
||
| - **Shared DB** (free): `#[shuttle_shared_db::Postgres] pool: PgPool` | ||
| - **AWS RDS** (paid): `#[shuttle_aws_rds::Postgres] pool: PgPool` | ||
|
|
||
| ## Secrets | ||
|
|
||
| Create `Secrets.toml` in project root, add to `.gitignore`: | ||
|
|
||
| ```toml | ||
| MY_API_KEY = 'your-api-key-here' | ||
| ``` | ||
|
|
||
| Use in code: | ||
|
|
||
| ```rust | ||
| #[shuttle_runtime::main] | ||
| async fn main(#[shuttle_runtime::Secrets] secrets: SecretStore) -> ShuttleAxum { | ||
| let api_key = secrets.get("MY_API_KEY").unwrap(); | ||
| Ok(router.into()) | ||
| } | ||
| ``` | ||
|
|
||
| ## Static Assets | ||
|
|
||
| Configure in `Shuttle.toml`: | ||
|
|
||
| ```toml | ||
| [build] | ||
| assets = [ | ||
| "assets/*", | ||
| "frontend/dist/*", | ||
| "static/*" | ||
| ] | ||
|
|
||
| [deploy] | ||
| include = ["ignored-files/*"] # Include files that are normally ignored by git | ||
| deny_dirty = true | ||
| ``` | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| 1. `shuttle run` - local development | ||
| 2. Use MCP server for AI-assisted development | ||
| 3. Use MCP server for Searching the Docs | ||
|
|
||
| ## Key Points | ||
|
|
||
| - Always use `#[shuttle_runtime::main]` as your entry point | ||
| - Configure static assets in `Shuttle.toml` | ||
| - Use secrets for sensitive configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| use anyhow::{Context, Result}; | ||
| use dialoguer::{theme::ColorfulTheme, Confirm, Select}; | ||
| use std::fs; | ||
| use std::path::Path; | ||
|
|
||
| use crate::args::AiRulesArgs; | ||
|
|
||
| /// Embedded content from ai-rules.md | ||
| const AI_RULES_CONTENT: &str = include_str!("../../ai-rules.md"); | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum AiPlatform { | ||
| Cursor, | ||
| Claude, | ||
| Windsurf, | ||
| Gemini, | ||
| Codex, | ||
| } | ||
|
|
||
| impl AiPlatform { | ||
| /// Get the relative file path for this platform | ||
| fn file_path(&self) -> &'static str { | ||
| match self { | ||
| AiPlatform::Cursor => ".cursor/rules/shuttle.mdc", | ||
| AiPlatform::Claude => "CLAUDE.md", | ||
| AiPlatform::Windsurf => ".windsurf/rules/shuttle.md", | ||
| AiPlatform::Gemini => "GEMINI.md", | ||
| AiPlatform::Codex => "AGENTS.md", | ||
| } | ||
| } | ||
|
|
||
| /// Get the display name for this platform | ||
| fn display_name(&self) -> &'static str { | ||
| match self { | ||
| AiPlatform::Cursor => "Cursor", | ||
| AiPlatform::Claude => "Claude Code", | ||
| AiPlatform::Windsurf => "Windsurf", | ||
| AiPlatform::Gemini => "Gemini CLI", | ||
| AiPlatform::Codex => "Codex CLI", | ||
| } | ||
| } | ||
|
|
||
| /// Get all available platforms | ||
| fn all() -> Vec<AiPlatform> { | ||
| vec![ | ||
| AiPlatform::Cursor, | ||
| AiPlatform::Claude, | ||
| AiPlatform::Windsurf, | ||
| AiPlatform::Gemini, | ||
| AiPlatform::Codex, | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| /// Handle the `ai rules` command. | ||
| /// Generates AI coding assistant rules files for the selected platform in the working directory. | ||
| pub fn handle_ai_rules(args: &AiRulesArgs, working_directory: &Path) -> Result<()> { | ||
| // Determine platform from args or prompt user | ||
| let platform = if args.cursor { | ||
| AiPlatform::Cursor | ||
| } else if args.claude { | ||
| AiPlatform::Claude | ||
| } else if args.windsurf { | ||
| AiPlatform::Windsurf | ||
| } else if args.gemini { | ||
| AiPlatform::Gemini | ||
| } else if args.codex { | ||
| AiPlatform::Codex | ||
| } else { | ||
| // Interactive mode - prompt user to select platform | ||
| select_platform_interactive()? | ||
| }; | ||
|
|
||
| // Write the rules file | ||
| let file_path = working_directory.join(platform.file_path()); | ||
| let file_existed = file_path.exists(); | ||
| let should_append = matches!( | ||
| platform, | ||
| AiPlatform::Claude | AiPlatform::Gemini | AiPlatform::Codex | ||
| ) && file_existed; | ||
|
|
||
| let was_written = write_rules_file(platform, working_directory)?; | ||
|
|
||
| if was_written { | ||
| let action = if should_append { | ||
| "appended to" | ||
| } else if file_existed { | ||
| "updated" | ||
| } else { | ||
| "generated" | ||
| }; | ||
|
|
||
| println!( | ||
| "✓ Successfully {} {} rules at: {}", | ||
| action, | ||
| platform.display_name(), | ||
| platform.file_path() | ||
| ); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Prompt user to select a platform interactively | ||
| fn select_platform_interactive() -> Result<AiPlatform> { | ||
| let platforms = AiPlatform::all(); | ||
| let platform_names: Vec<&str> = platforms.iter().map(|p| p.display_name()).collect(); | ||
|
|
||
| let selection = Select::with_theme(&ColorfulTheme::default()) | ||
| .with_prompt("Select AI coding assistant") | ||
| .items(&platform_names) | ||
| .default(0) | ||
| .interact() | ||
| .context("Failed to get platform selection")?; | ||
|
|
||
| Ok(platforms[selection]) | ||
| } | ||
|
|
||
| /// Write the rules file to the appropriate location. | ||
| /// Returns Ok(true) if the file was written, Ok(false) if the user aborted. | ||
| fn write_rules_file(platform: AiPlatform, working_directory: &Path) -> Result<bool> { | ||
| let file_path = working_directory.join(platform.file_path()); | ||
|
|
||
| // For top-level markdown platforms (Claude, Gemini, Codex), append to existing file instead of overwriting | ||
| let should_append = matches!( | ||
| platform, | ||
| AiPlatform::Claude | AiPlatform::Gemini | AiPlatform::Codex | ||
| ) && file_path.exists(); | ||
|
|
||
| // Check if file already exists | ||
| if file_path.exists() { | ||
| let action = if should_append { | ||
| "append to" | ||
| } else { | ||
| "overwrite" | ||
| }; | ||
| let confirm = Confirm::with_theme(&ColorfulTheme::default()) | ||
| .with_prompt(format!( | ||
| "File {} already exists. {} it?", | ||
| platform.file_path(), | ||
| action | ||
| .chars() | ||
| .next() | ||
| .map(|c| c.to_uppercase().collect::<String>()) | ||
| .unwrap_or_default() | ||
| + &action[1..] | ||
| )) | ||
| .default(false) | ||
| .interact() | ||
| .context("Failed to get confirmation")?; | ||
|
|
||
| if !confirm { | ||
| println!("Aborted."); | ||
| return Ok(false); | ||
| } | ||
| } | ||
|
|
||
| // Create parent directories if they don't exist | ||
| if let Some(parent) = file_path.parent() { | ||
| fs::create_dir_all(parent) | ||
| .context(format!("Failed to create directory: {}", parent.display()))?; | ||
| } | ||
|
|
||
| // Write or append the content | ||
| if should_append { | ||
| // For top-level markdown files (Claude, Gemini, Codex), append the AI rules to existing file | ||
| let existing_content = fs::read_to_string(&file_path).context(format!( | ||
| "Failed to read existing file: {}", | ||
| file_path.display() | ||
| ))?; | ||
|
|
||
| // Add separator and append new content | ||
| let combined_content = format!("{}\n\n{}", existing_content.trim_end(), AI_RULES_CONTENT); | ||
|
|
||
| fs::write(&file_path, combined_content) | ||
| .context(format!("Failed to append to file: {}", file_path.display()))?; | ||
| } else { | ||
| // For other platforms or new files, write/overwrite the content | ||
| fs::write(&file_path, AI_RULES_CONTENT) | ||
| .context(format!("Failed to write file: {}", file_path.display()))?; | ||
| } | ||
|
|
||
| Ok(true) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
style: String capitalization logic assumes ASCII first character. Use
to_uppercase()instead for proper Unicode handling.Prompt To Fix With AI