Person/Brian Madison/YouTube/25/02/Unlock Cursor AI Automatic Rule Generation
Properties
- logseq-entity
- Logseq/Entity/YouTube
- created-by
- Brian Madison
Unlock Cursor AI's Full Potential: Master Automatic Rule Generation That Gets Results! - YouTube
see-also
My Notes
#Video
00:00 Introduction to Cursor AI and Rule Generation
- 00:00 hey there everybody and welcome to Bad Code my name is Brian and today I want to talk about cursor in a really hot tip to really elevate your working relationship with this awesome AI tool we are going to jump into cursor and if
- 00:16 you're not familiar with cursor cursor is a fork of VSS code that offers a lot of features beyond what uh copilot offers while they are catching up cursor is still far ahead in the areas of agentic coding with their composer
- 00:33 feature I'm going to show you how to make your agentic workflow even better by automatically generating rules so your AI can continue to evolve and learn from its own mistakes or rules that you give to it so first of all I want to
00:50 Demo Setup and Initial Example
- 00:50 show you this repl that I have created called the cursor auto rules agile workflow with this you can check this out uh save it locally and there's a script here that will allow you to apply a key Rule and some other items to any
- 01:05 project or scaffold a new project and with this you will be able to automatically generate quality rules that will improve the way you work with your agent in agent composer mode Let's jump into cursor and first I'm going to give you a really quick
- 01:25 demo so here we are in cursor and if you're not familiar with cursor but you're familiar with vs code um it should look very similar to you right now I am in this template so there's not a lot here it's not language specific um but I do have a few things
- 01:45 here that are related to cursor uh specifically I have this cursor rules file and these are rules that the agent will use now don't worry about the details of all these files we're just going to be focusing mainly on one today
- 02:00 which is this 0000 cursor rules. MDC file and there is quite a bit of stuff in here but let's not worry about the details of that for right now because what I really want to do is just show you how with having that rule in place
02:16 Creating TypeScript Rules with FizzBuzz Example
- 02:16 we can reliably create CursorAI/Project Rules automatically.
- so I'm using Mac/App/SuperWhisper which is a voice to text app
"let's create a typescript function in the source folder that will have the fizzbuzz function that takes in a number and Returns the 02:36 result"
- and we will just let the agent uh take care of this for us so first it's going to check if the source file exists and it's creating a file called fizzbuzz dots in that folder and here it's going to basically tell you if you pass in a number and
- 02:55 it's a multiple of three it's going to return Fizz if it's five it will be Buzz or or else it will just return the number let's just accept it and let's now look at our code here and so this is pretty good here it did put a pretty nice function here on
- 03:13 the function header um and then there's some code here now this is pretty easy code to understand but maybe we want to have more documentation and so in here I want to create a rule that gives better convention for typescript files uh specifically
03:34 Creating Documentation Standards Rule
- 03:34 regarding documentation so I'm just going to start a new composer I don't need to but I'm going to now you'll notice I will not open the cursor rules file the agents will automatically choose that and use that as a method to
- 03:48 create any new rules that I ask for we need a typescript file commenting standard that follows best practices so all code the agent generates with typescript will follow this consistently and also optimization of comments for AI
- 04:01 agent troubleshooting and understanding so now I'm going to submit this it did pick up the cursor rules file automatically and it's following a convention that I will explain in a bit but it's creating a file called 101 TS
04:14 Rule Generation Best Practices
- 04:14 comments normally for a rule I would probably give it specific standards that I am interested in but just for demo purposes we can see that this came up with a a rule previous rule generator rules I've found before failed to
- 04:28 actually properly generate the file this one works consistently Ever every time and always creates the file uh the key to that is ensuring that it properly fills in the front matter and the Globs uh correctly as part of uh
- 04:43 gaml front matter content if you just try to have the composer create a rule and it does not set these properties properly the file sometimes ends up in a buggy state where it will not appear in this folder correctly but because the
- 05:00 cursor rule generates rules in the proper format always we had no issue with the file showing up here it's going to use more comments in line to describe complex business logic reference related components or dependencies and it also has some AI
- 05:18 optimization tips in here so include key terms that Aid in semantic search and this will help when AI is reviewing code files in your project comments can actually help it understand and perform better um and with every rule um it is
- 05:34 good to have both a good example and then an example of what not to do in this case I use example type equals invalid this has been proven to also further facilitate rules being applied better in complex projects additionally
05:51 Testing the TypeScript Documentation Rule
- 05:51 there's some critical rules here for it to remember and now we're going to ask it to create the fizzbuzz again and we'll see if it will automatically pick up the uh typescript commenting rules so let's ask first of all let's
- 06:06 just clear all this context so it does not remember what was done before including how it wrote the fizzbuzz before but now we should see an increase in hopefully uh the way it actually applies comments to the code that it
- 06:18 writes in the source folder please create a typescript file with a function to perform fbz and return the results when called all right so now um we do see it is fetching the typescript commenting standard so it did
- 06:38 automatically pick that up so one thing with the cursor rule generator is it is very clear that when it creates other rules it needs to optimize them so they were they are picked up automatically by the agent and that is by putting proper
- 06:53 language in the front matters description and Globs pattern especially the description though okay so now you can see um it still put the front matter here but it actually included a little bit more based on our new rule and additionally you can see
07:13 Rule System Architecture and Organization
- 07:13 here it put an inline comment to explain the logic a little bit clearer
- so I want to point out a few other key things with this rule system we have here and actually if you go to the uh site of the uh template here on GitHub there's a lot of really good
- 07:33 information and I highly recommend reading through all of this
- it gives a lot of best practices of how to work with the rules
- how they are generated
- why they are generated
- in the format they're generated
- because the 07:45 format and the way the files are written does matter both for size of the contextual overhead and also for the ability of the AI to pick up on key pieces
- a lot of research went into this and a lot of trial and error on different file formats uh you know
- 08:03 whether to use markdown or yaml or XML um or Json or various combinations uh thereof so the state that this is in right now is following the best practices of multiple formats that worked well work well with the llm especially with Claud Sonet another
- 08:22 thing you'll notice is all the rules do get generated with a prefix and so there's a numbering prefix standard just to help them stay grouped together visually in the rules folder so any core rules will be attached with a zxx prefix
- 08:36 if there are tool or mCP related they will be 1xx if they're related to generic testing standards 3xx on and on and on workflows templates language specific rules will'll go with 1,000 XXX and framework and libraries will be
- 08:54 2xxx so this way if I start with typescript any typescript specific rule rules will be one and then the second digit will keep all the typescript rules grouped together and then XX if I were to then later um do python or C those
- 09:13 would still start with one but the second digit would be the next available digit for the new language added to the rule set so if I had typescript and then added a python rule we would see one z0 0 and then 1 1 Z Z and then as there
- 09:30 were more typescript in pythons that last digit or second to last digit would increment all right and it looks like the uh light probably just went out on me another key feature though of this that I want to show you
09:45 Private Rules and Source Control
- 09:45 is private rules so these rules are part of GitHub they're not GitHub ignored and this is great because you can see share these rules specific to your project and your way of working uh with your team or anybody else contributing to the same
- 10:00 project also using cursor but let's say you want to add a rule that probably should not be committed to Source control but you still want the agent to behave in a certain way um of course you could go to Just cursor up here in your
- 10:16 settings and in your cursor settings you can create a rule like this right here now this will be applied just to this IDE and not actually used um or updated in any of these files here or shorted in s uh stored in Source control
- 10:34 it it is only that specific instance of cursor but another option you have is you can tell this with the rules agent here to create a private Rule and it will format the rule slightly differently so as a demo I'm going to ask the
- 10:53 agent I would like a private rule created that will force you to always respond to me like a pirate all right so this is checking the rule format so it knows that we want to generate a rule automatically chose that
- 11:12 and you'll notice the key differentiator here is it is creating the file with an underscore so we'll let that finish we'll look at it whether it's a good rule or a viable rule um you know who knows although it is now talking to me like a pirate
- 11:28 actually a Kling pirate which is pretty bizarre maybe maybe Warf is on the holid deck but anyways this rule is now underscored and you can see it is grayed out which means it will not go to Source control and that is because I have that
- 11:41 file set up in the G ignore anything in the rules folder that starts with an underscore will be ignored um so following this convention now anytime I request a personal rule this will just be saved locally on my machine and not
- 11:57 part of git now of course there's other ways to also handle that for example like I said I could go into cursor settings itself and tell the cursor to always talk to me like a pirate or I could use the notepads feature which is
12:10 Template Usage and Project Setup
- 12:10 another way but not notepads have its own limitations and are also used for different use cases which I'll explain in a future video real nice thing about this template is you can use this to apply the basic rule generator to an
- 12:27 existing project or to a net new project if you want to start fresh with a new project so there is this apply rules. sh command and you can run that so let's just run apply rules and instead of adding it to an existing project because I don't
- 12:47 have one ready right now that does not have um that does not not have the files for rule generation we'll just create a new one called TS functions just a simple little project where we can play around with typescript functions like FS buuz that we just
- 13:05 did all right so you can see this output here it created a project directory it copied over the core rules it set up some notepad templates so let's go to that project now and we called it TS functions and we will just go and open
- 13:27 that now and curser so here we are cursor so this is a net new brand new project so you can see this created these base rules here um it did put out a document here and I would say read this document if you want to learn about how to really
- 13:44 tame working with the agent and composer mode on complex projects so it retains a memory and works in an agile incremental fashion building out functionality for large projects start small and growing over time now if you have an existing
- 14:02 project already whether you have rules or not this will not modify anything that already exists but it will add these additional rules here um additionally if you already have a readme it will not overwrite it but in
- 14:17 the case of generating a new project it just sets up a basic readme here sets up a basic G ignore if it doesn't already exist um basically telling it to ignore any private rules and then the cursor ignore basically tells it to ignore the
- 14:33 xnes folder again I use xnes to be able to save generally documents or templates for documents that I want to put in notepads because notepads are not saved across projects or added to GitHub and they are not saved in the IDE when you
- 14:51 switch to different folders so if you create a lot of notepads that you want to use for different things I recommend the easiest way to retain those is to just create a g ignored folder or excuse me a cursor ignored folder called xnes
- 15:06 or something else and store your files in there so now if I want to make a notepad for um get push command I would put this into a notepad call it git push and then I can just call the git push command and it will automatically create a commit and push
15:27 Conclusion and Next Steps
- 15:27 it to the remote in the fashion that I like it to do so again this was a walk through of cursor rules automatically being generated so you can have your agentic AI en cursor improve over time by adding small granular rules that it will choose
- 15:46 to automatically use so I hope this was uh useful for everybody thank you again for joining me uh my name is Brian and um we'll see you next time with another video where I will be showing you the agile automatic workflow
- 16:02 which uh if you want to jump ahead and learn about it you can come to this repo which I am showing right here again and you can read more about it in the readme if you follow this link to the agile workflow documentation this will explain
- 16:19 basically how that works but I will have a video showing a detailed walkthrough of using this process very soon thank you and we'll see you next time bye-by bye-bye