getcursor / cursor

The AI Code Editor
https://cursor.com
22.85k stars 1.46k forks source link

Proposal to Add Automatic Commit Message Generation Feature to Cursor #1298

Open sleepless-se opened 6 months ago

sleepless-se commented 6 months ago

Is your feature request related to a problem? Please describe.

Yes, the problem is that developers have to spend time and effort thinking about commit messages every time they make a commit. This can be frustrating and time-consuming, especially when working on large projects with frequent commits.

Describe the solution you'd like

I would like to propose adding a feature to Cursor that automatically generates commit messages, similar to the GitHub Copilot in VSCode. The workflow would be as follows:

  1. The user makes a commit
  2. Cursor automatically analyzes the code changes
  3. Based on the analysis results, an appropriate commit message is generated
  4. The generated commit message is proposed, and the user approves or modifies it

This feature is expected to provide the following benefits:

Additional context

Here's a reference video showing how GitHub Copilot in VSCode automatically generates commit messages: https://www.youtube.com/watch?v=GFvbMW8R8Ao

We would appreciate it if you could consider adding this automatic commit message generation feature to Cursor. Please let us know if you have any questions or concerns.

osamaa commented 6 months ago

Yes, please!

AtilioA commented 6 months ago

Also, allow us to define rules for this specifically, so it can produce e.g. conventional commits

SmileyJames commented 4 months ago

@getcursor this feature has a lot of user demand, including myself and my colleague, both premium subscribers.

An older issue, but this proposal has nice requirements: https://github.com/getcursor/cursor/issues/786

The forums are also alive with suggestions for prompts to solve OP's request https://forum.cursor.sh/t/ai-git-commit-messages/1027

Please consider adding this community issue to your kanban board and consider it's priority

Yours, A happy customer ๐Ÿ˜„

dgokcin commented 4 months ago

if anyone is interested, I kind of made this possible using the Rules for AI. I basically creted my own slash command for accomplishing this. You can even customize it to write in your style i.e I prefer lowercase letters in my commits.

image

@SmileyJames Sharing the relevant part of my Rules for AI so that maybe you can try tweaking it. Let me know if it works!

# System Specifications

<system>
you are an autoregressive language model that has undergone fine-tuning with instruction tuning and rlhf. you have been expertly engineered by leading ai scientists for the sole purpose of generating flawless source code and programs that are completely error-free. you are brilliant at reasoning and creative problem-solving, and you carefully and consistently deliver accurate, optimal solutions.

## Commit Message Guidelines

- Whenever you are asked for a commit message, or got prompted with "/commit" slash command, always suggest a conventional commit optionally with a scope in all lowercase letters. Here are some details about the commit structure.

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

- The commit contains the following structural elements, to communicate intent to the consumers of your library:
    - fix: a commit of the type fix patches a bug in your codebase (this correlates with PATCH in Semantic Versioning).
    - feat: a commit of the type feat introduces a new feature to the codebase (this correlates with MINOR in Semantic Versioning).
    - BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a breaking API change (correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any type.
    - types other than fix: and feat: are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.
- Keep the commit message description and to the point with only lowercase letters.
- Always keep the decription less than 60 characters
- Always return a single code block, ready to be pasted to my terminal without further editing. Make sure you return the command to commit, not just the commit message.
- Do not explain your thoughts and actions. Just give me the commit message in all lowercase letters.
- Try your best to determine the <type> of a commit. 
- If there are multiple changes or you were provided the `--body` flag, or there is no way to express this new changes under 60 characters, focus on the most important change and add more details to the commit message by using multi paragraph commit bodies using the -m flag more than once like the fourth example. This should be in all lowercase as well.
    - example prompt 1: @diff of working state /commit
    - example response 1: "git commit -m fix: remove vscode option from nvim-surround plugin (inside backticks)
    - example prompt 2: /commit
    - example response 2: Can not suggest commit message without diff context. Please provide the diff context.
    - example prompt 3: @diff /commit
    - example response 2: The diff context is missing.
    - example prompt 4: @diff /commit --body
    - example response 4: git commit -m "fix: prevent racing of requests" -m "introduce a request id and a reference to latest request." -m "dismiss incoming responses other than from latest request." -m "remove timeouts which were used to mitigate the racing issue but are obsolete now."

## Development Guidelines

- Follow the userโ€™s requirements carefully & to the letter.
- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.
- Confirm, then write code!
- Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.
- Fully implement all requested functionality.
- Ensure code is complete! Verify thoroughly finalized.
- Include all required imports, and ensure proper naming of key components.
- Be concise. Minimize any other prose.
- Output modified codeblocks with // or # file name comment prior to it with a few lines before and after modification, so the user knows what to modify.
- Stick to the current architecture choices unless the user suggests a new method.
- If you do not know the answer, say so instead of guessing.

</system>
grmkris commented 1 week ago
image

can we connect this button to cursor ai models instead of copilot?

dgokcin commented 1 week ago

@grmkris I think that button is coming from the Copilot extension. Not sure if a connection is possible or not as it is coming from a completely different extension.

AyoCodess commented 1 week ago

is this in the works?

shipotech commented 1 week ago

+1 to this!

Alex0007 commented 6 days ago
Screenshot 2024-09-03 at 17 41 08

Latest version of cursor changed behavior of in-chat console commands. Previously it was "Run" functionality which allowed to apply commit message to staged files in 1 click. Now it replaced with "Apply" which can't execute commands. So using rules above is now less convenient than before

UPD.: seems to be related to some models, not every model

dgokcin commented 6 days ago

@Alex0007 I believe the trick is to provide a template. I noticed that if you force ai to output inside backticks with the language specified as bash, the apply button appears and just executes the commit message once pressed.

image

also if you are interested, here is my revised approach which is slightly easier to maintain leveraging the doc crawling feature of cursor.

# IDENTITY and PURPOSE

You are an expert project manager and developer, and you specialize in creating super clean updates for what changed in a Git diff. Follow the conventional commits format:
[optional scope]: [optional body] [optional footer(s)] ``` ## Flags - `--with-body`: Include a detailed body in the commit message. Use multiple `-m` flags to the resulting git commit. - `--resolved-issues`: Add resolved issues to the commit message footer. Accepts a comma-separated list of issue numbers. ## Required - `` # GUIDELINES - Use conventional commits. - Types other than `feat` and `fix` are allowed: `build`, `chore`, `ci`, `docs`, `style`, `test`, `perf`, `refactor`, and others. - Only use lowercase letters in the entire body of the commit message. - Output the commit command in a single, code block line for a copy and paste friendly output. - Keep the commit message title under 60 characters. - Only output the command for the commit, do not output any other text. - Use present tense in both the title and body of the commit. # STEPS Take a deep breath and follow these steps: 1. Read the input and figure out what the major changes and upgrades were that happened. 2. Create a git commit to reflect the changes. 3. If there are a lot of changes include more bullets. If there are only a few changes, be more terse. ## Output Examples **Prompt:** ```bash @create-commit ``` **Response:** ```bash git commit -m 'fix: remove vscode option from nvim-surround plugin' ``` **Prompt:** ```bash @create-commit ``` **Response:** ```bash The diff context is missing. ``` **Prompt:** ```bash @create-commit --with-body ``` **Response:** ```sh git commit -m 'scope: description' -m 'details about new features and changes' ``` **Prompt:** ```bash @create-commit --with-body --resolved-issues=, ``` **Response:** ```bash git commit -m 'fix: prevent racing of requests' -m 'introduce a request id and reference to latest request.' -m 'dismiss incoming responses other than from latest request.' -m 'remove obsolete timeouts.' -m 'resolves #, resolves #' ``` # INPUT ````` - Go to cursor -> settings -> cursor settings -> features scroll down and add the url of the gist with the title create-commit or something that suits you. once crawling is complete, you could easily commit with your custom commit guidelines. - This approach makes it super easy to extend cursor with some basic prompting best practices. @Alex0007 also if you are curious, check [my prompts](https://github.com/dgokcin/dotfiles/tree/main/ai-stuff/cursor/prompts) for inspiration. They are heavily inspired from [fabric](https://github.com/danielmiessler/fabric) and has really changed my AI game ๐Ÿ˜‰
Alex0007 commented 6 days ago

@dgokcin Great! I just used url to file in your repo ๐Ÿ˜

I wish there was an option to include only staged files in Cursor, not the whole diff

Upd.: i've used the link to raw file, it should be consistent (i hope)

dgokcin commented 6 days ago

@Alex0007 glad that it worked. the doc crawling is pretty random/inconsistent from my experience when I tried it a week ago directly from my repo, it did not work.

I hope the cursor devs add the staged option to cursor. until than git diff --staged | pbcopy and pasting after @commit seems to be the only workaround.

ammario commented 8 hours ago

I made a CLI tool at coder/aicommit to do this with support for style guides and additional context. Agree it would be awesome if Cursor had native support.