-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: define thoughtbot rules for AI-enabled IDEs #764
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: main
Are you sure you want to change the base?
Conversation
During a Fusion AI task force meeting, we discussed the tools we use and how we enforce rules. As part of that conversation, we decided it would be valuable to define official thoughtbot guidelines for editors that integrate AI, such as Cursor. This PR opens the discussion by proposing an initial set of rules I put together. These are meant as a starting point.
rails/ai-rules/rails-rules.md
Outdated
Key Conventions | ||
- Follow RESTful routing conventions. | ||
- Use concerns for shared behavior across models or controllers. | ||
- Implement service objects for complex business logic. |
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.
I'm not 100% sure about this for example. Lately I've been more leaning towards Service objects are poorly-named models.
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 is the controversial one! My personal opinion is that service objects are an anti (or at least overused) pattern and should only be a fallback when other patterns don't fit.
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.
I also have veered towards treating service objects as an anti-pattern in many situations. I even have a note with giant list of what other design patterns or common constructs a service object frequently is trying to become.
@laicuRoot thanks for starting this! I'm curious if you added each line as a consequence of the AI performing poorly on something? Or did you add things from our existing guides that seemed useful? Some of these things eg. naming conventions I haven't had any trouble with (I'm using Claude Code). I think it would be good if we can avoid adding things that don't improve the situation so we have a list that is maintainable. Based on my Claude Code usage and observing when it doesn't perform so well I've added the following to my
Some things here, mostly around the commit message guidance is too personal / prescriptive and don't think we'd want that in shared rules. |
- Use ActiveRecord effectively for database operations. | ||
|
||
Syntax and Formatting | ||
- Follow the Ruby Style Guide (https://rubystyle.guide/) |
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.
I think I would opt to solve this with a hook (or similar) that runs Standard at the end.
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.
I didn't know about hooks 🤔 thank you for sharing this. I guess we can include hooks within the guides?
Syntax and Formatting | ||
- Follow the Ruby Style Guide (https://rubystyle.guide/) | ||
- Use Ruby's expressive syntax (e.g., unless, ||=, &.) | ||
- Prefer double quotes for strings. |
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.
I've definitely seen this. Again I wonder about something that runs Standard at the end
rails/ai-rules/rails-rules.md
Outdated
|
||
Testing | ||
- Write comprehensive tests using RSpec. | ||
- Follow TDD/BDD practices. |
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.
One thing I haven't experimented with yet is instructing it to follow TDD, but it's on my list. Does it follow this process?
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.
It does not follow the process in terms of suggesting the test first and then the code but, at least, it includes tests for every single class or change in the logic that is adding.
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.
I have gotten LLMs to do true red/green/refactor TDD. This has been with one-off agent sessions in my editor (both Claude and GPT) with an initial prompt rather than extracting to a rule though.
Good question @jaredlt. I’ve included items from existing guides that I thought would be helpful for the AI to take into account. I also added sections like the one on testing after noticing that the AI wasn’t suggesting tests. I’ve been using this setup since I subscribed to Cursor about two months ago. |
Yes, I completely agree. I like yours actually 👍 short and to the point. |
@rdnewmanbot we were just talking about this yesterday! |
rails/ai-rules/rails-rules.md
Outdated
- Optimize database queries using includes, joins, or select. | ||
|
||
Key Conventions | ||
- Follow RESTful routing conventions. |
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.
Should we specify that this means sticking to the 7 restful actions: index, show, new, create, edit, update, delete? I'm not sure what the ideal level of detail is in a rules file.
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.
I think it is a good idea to be detailed about this. I also found that if you add a link to a blog post or source that explains the rule, it considers the content of the blog post too.
rails/ai-rules/rails-rules.md
Outdated
Testing | ||
- Write comprehensive tests using RSpec. | ||
- Follow TDD/BDD practices. | ||
- Use factories (FactoryBot) for test data generation. |
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.
Is it worth suggesting that test setup should be local? Tell the AI to optimize for readability and changeability? Otherwise I find that LLMs love to create deeply nested contexts with let
.
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.
I think it might be worth addressing let
statements and preferring an approach of keeping test cases self-contained rather than keeping the spec file DRY.
@jaredlt if you're using Claude Code, there's a setting to have it not add the co-authored by line to your commit:
|
This may be a bit controversial. There is evidence that AI models tend to perform better if threatened.
|
I’ve pushed an update that keeps only the suggestions and rules based on my experience using Cursor. I like @jaredlt approach of keeping it concise, focusing just on instructions to correct behaviours we don’t want when using the AI as a pair programming partner 🙂 |
3f6a363
to
b5ef9b8
Compare
I saw this recently shared in an official vscode update. https://gist.github.com/burkeholland/a232b706994aa2f4b2ddd3d97b11f9a7 I don't think this is what we want but it is interesting to see how people are iterating and creating versions of these instructions. Maybe we can version this script and experiment with it. |
Do we feel this is good enough to merge? |
@laicuRoot I will experiment using these rules for a bit. One thing I noticed is that I don't know how well it works to have links in there and assume the model will look them up. When I asked the model if it will look up those links it said:
|
I love the idea of defining thoughtbot rules! It would be neat if we could somehow just generate rules based on our existing guides that auto-update when those change, maybe we could use AI to generate rules based off of them 😆 |
@samithoughtbot Claude Code claims it will use links:
This has me wondering: how different are best practices in instructions for different models/agents? 🤔 |
During a Fusion AI task force meeting, we discussed the tools we use and how we enforce rules. As part of that conversation, we decided it would be valuable to define official thoughtbot guidelines for editors that integrate AI, such as Cursor.
This PR opens the discussion by proposing an initial set of rules I put together. These are meant as a starting point.