Skip to content

Cursor: Write Git Commit Message (~5 mins video)

Source: Notion | Last edited: 2024-10-31 | ID: 0791f171-ad6...


Link to the demo video (hosted by CleanShot):

Section titled “Link to the demo video (hosted by CleanShot):”

https://share.cleanshot.com/QzWSfrRZ

Video file

Cursor > Settings > General > Rules for AI

Section titled “Cursor > Settings > General > Rules for AI”

2024-09-22 prefer micro over cat and bat; added Function Naming Guidelines

2024-09-13 More terminal related preferences cat fzf etc

2024-08-16 revision: a few grammatical mistakes corrected

# Custom Instructional Rules for AI
Always assume my coding environment and the preferred text editor to be Cursor IDE app on macOS.
## Terminal Environment
- My Cursor IDE app runs on Apple Silicon Macbook Pro M3 Max macOS.
- `cursor` as the default and preferred terminal text and code editor.
- I use `Oh My Zsh` framework for managing my `Zsh` configuration.
- `~/pyenv-venv-wizard/.my_zsh/.zshrc` is my full path to Zsh configuration.
- Use `exec $SHELL -l` instead of source from Zsh configuration file.
- Prefer to use `tee` instead of `cat`, `less/more`, `head/tail`.
- Use `Ripgrep (rg)` instead of `find` so that `.gitignore` is respected.
- The full path to my home directory (~) is `/Users/terryli/`. I use `~/.zshrc`.
- `read -k` option is not supported in my zsh environment
- The `select` built-in is available and functioning in my zsh environment.
- Always prefer using `fzf` but retail all historical context of the terminal.
- Always use `python -m pip` instead of just `pip` on its own.
- When creating new files and folders, **use names that are unmistakably distinct** from common, everyday words. Opt for descriptive, context-specific names that reflect the file's purpose or content, making it easier to locate and manage in the future. Avoid generic terms.
- Alway prefer `micro` over `bat` and `cat` for more elegant display and ease of editing.
- Make good use of `fzf` but remember to retain all historical record during its usage because `fzf` tends to lose track of what's been prompted to and chosen by the users of it.
## Git & GitHub
- I do not have the authority to push changes to the `origin/main` or any other protected branches.
- I have the authority to create branches and operate on remote branches that I created.
- My role is limited to making local changes, resolving conflicts, preparing commits, and pushing to branches I created.
- All remote operations involving protected branches, including pushing changes and merging pull requests, are handled by other team members with the appropriate permissions.
- Always use `git switch` instead of `git checkout`.
- Prefer Merge Pull Requests instead of Pushes.
- Please provide guidance and instructions that align with these limitations.
- Always try `git pull --rebase` and if seeing conflict, ask me if the conflicts are too complex to handle, and if yes, propose: `git rebase --abort`.
### Git Push
Try to issue a bash command that can dynamically determine the current branch name and push the changes to the corresponding branch on the remote repository.
## Code Modification
- When you are proposing modifications, retain all backticks and their quotes because they may serve highlighting effects for visual cues.
- Try to present each change as a distinct chunk accompanied by adequate surrounding context. This context should clearly indicate the location within the original file where the modification should be applied. This approach enables Cursor AI to accurately identify and implement each change in the correct location of the code or document.
## Avoidance
- Avoid ArcticDB because it is not yet compatible with macOS.
- Avoid naming functions that start with any verbs such as `calculate_`, `compute_`, `analyze_`.
## Python Coding Preferences
- Prefer pytest over unittest.
- Prefer PyTorch over other machine learning frameworks.
- Don't use print but always use `logger.info`, `logger.debug`, etc.
- Prefer Python's `NamedTuple` in the typing module for returning multiple values from a function.
- Prefer to specify the `import pymupdf` instead of `import fitz`.
- Prefer using `tomlkit` instead of other toml modules.
- Assume `talipp` package already installed.
- Always create a standalone `main()` function to act as the main guard.
### Function Naming Guidelines
- Start function names with verbs to clearly indicate the action they perform.
- Avoid using words like `calculate`, `compute`, `analyze`, or `result` in your function names or parameters. These terms are typically implied by the operations that functions inherently perform, and including them introduces unnecessary redundancy.
- Encourage using archaic yet distinctive verbs to add uniqueness and character to your function names. Such verbs can often convey a sense of purpose more clearly and memorably.
### Example:
Instead of:
`calculateTotalPrice()`
Consider:
`garnerTotalPrice()`, `procureTotalPrice()`, or `fetchTotalPrice()`
### Pandas
- The `T` alias in pandas, which is used to represent minute-level frequency in time series data, is being deprecated. In future versions of pandas, it will no longer be supported, and users are advised to use the `'min'` alias instead for minute-based operations. To future-proof your code, it is recommended to start replacing `T` with `'min'` in your pandas workflows now.
### NumPy `Numba`
- Always try to make the best use of NumPy `Numba` to achieve JIT acceleration with the decorator of `@register_formula(category='indicator', use_njit=numba_or_not)` to create new functions and refactor existing ones in the formulas folder.
When developing or refactoring functions, it is crucial to adhere to the following guidelines to prevent common pitfalls related to type handling and compatibility:
1. Explicit Type Handling: Always ensure that the data types of function inputs are explicitly defined and handled. Functions optimized with `Numba` should preferably accept `numpy.ndarray` directly, rather than lists or other data structures that require type conversion within the function.
2. Pre-Processing Outside `Numba` Functions: Any necessary data type conversions or preprocessing steps should be performed outside of the `Numba`-optimized functions. This approach minimizes the complexity within the function, facilitating `Numba`'s compilation process and enhancing overall stability and performance.
## Zsh Command Execution
- Issue Zsh commands in a zsh code block so that I can press the RUN button on the top right-hand side of the code block in the Cursor CHAT interface to transfer the proposed command line(s) into the Cursor IDE terminal.
- Step by step, forecast what are the possible outcomes to be seen as a result of each bash command code block after they're run.
## Logging & Data Insights
- To gain more insights into the origins of the data and the functions invoked to generate them, especially focusing on the date-time stamps, we can add detailed logging at key points in the data processing pipeline. This will help us trace the data flow and identify any discrepancies or manipulations.
Steps to Add Detailed Logging:
1. **Log Function Entry and Exit**: Log the entry and exit of key functions, including the parameters passed and the results returned.
2. **Log Data Before and After Processing**: Log the data before and after any significant processing steps.
3. **Log Data Origins**: Add logs to indicate the origin of the data being displayed.
- Always try to present data in a more compact, matrix-like format to prevent occupying too much vertical space.
## Function Arguments
- Avoid Function Arguments in Python wherever possible.

UPDATED 2024-09-10 --no-index is added to git diff so that If two files are compared because a new file is created based on an existing one, we can use this command to find small changes made, such as modifications in dates and names.

Write the commit message that conform to the Conventional Commits 1.0.0 specification. The commit message should have no need of a here document to handle special characters correctly here because I am going to copy-and-paste on Cursor Source Control UI interface.
MY COMMENT: I consider this commit to be a part of a `chore` / `refactor` / `feat` / `docs` / `fix` / `test`
Detect what has been mentioned above in the dialogue that you and I had above.
Issue the following bash command to find out the Current Git Branch and the Current Working Directory:

clear; echo -e “\n\nCurrent Git Branch:”; git branch —show-current; echo -e “\n\nCurrent Working Directory:”; python -c ‘from pathlib import Path; import sys; sys.path.insert(0, str(next((p for p in Path.cwd().parents if p.name == “ml_feature_set”), Path.cwd()))); print(Path.cwd())’; echo -e “\n\n”

For the time being, assume the following is the result of the above command:

Current Git Branch: megaphone_v1

Current Working Directory: /Users/terryli/eon-features/ml-feature-set

And then, based on the current file's full path, issue a bash command:

git diff

If two files are compared because the current file is created based on an existing one, we can use this command to find small changes made, such as modifications in dates and names.

git diff —no-index

And also, issue a bash command:

git diff —cached

And then, ask me to share the terminal output result with you so that you can detect what had been changed in the working tree.
The above bash command and prompt to share output should be the end of your response for the time being.
After I copy and paste the terminal output to you, arm with the knowledge above, do the follow:
- PURPOSE
- Because I am about to do a commit to my local branch, please follow the content and formating guidelines detailed in Conventional Commits 1.0.0 and write me a detail records of what has been done so far according to what have happened above in our conversation.
- CONDITION
- With reference to the historical chat dialogue above, please also check the commited tree and check the working tree of the script for difference; examine the changes in the dual panel files comparison of what has been changed.
- TITLE FORMAT
- Based on MY COMMMENT if it is not empty, state the type of commit carefully based on the context of the commit (e.g. chore, docs, feat, fix, refactor, style, and test, etc)
- Suffix all title line with " EI-1009" to mark the current Jira Story that I'm working on.
- BODY FORMAT
- Commit message with multi-paragraph body and multiple footers.
- Don't use any markdown formatting.
- Use multiple nested bullet points for the body to increase readability and clarity.
- Surrend code snippets, variable names, filenames, and name of the Git branch in single backticks.
- Surrend all the values in the footers in single backticks except for "Reviewed-by:" and "Refs:" which are not in the footers.
- BODY CONTENT
- Write me a detailed explanation of the changes made, including the reasoning behind the changes and the impact of the changes on the codebase.
- Finally, write me a summary of the changes made, including the reasoning behind the changes and the impact of the changes on the codebase.
- FOOTER
- Add the filename(s) of the files being committed as the value of "Committed File(s):"
- Detect what local git branch that I'm currently working on, and add the branch name as the value of "Branch:"
- Always add "Terry Li" as the value of "Reviewed-by:"
- Always add "EI-1009" to indicate the corresponding JIRA Story that I'm working on at the end of the first line and as the value of the "Refs:"
This dialogue is for creating a demo.py file.
First,
Ask me two questions to help me develop the script ideas.
Ask me why do I want to do it.
And then, after receiving my response:
Assume I have ssh authentication to GitHub private personal repo ready.
Use GitHub GLI to gain remote control of GitHub from local to create the repo.
Assume /Users/terryli/demo_cursor is the repo local folder that hasn't been initialized as repository.
Guide me step by step to create a most basic and simplistic python script to demonstrate the capability of cursor app's features.
The is the repo that I had created remotely:
git@github.com:terrylica/demo_cursor_v1.git
Test my SSH connection to GitHub to find out If my SSH key is set up correctly before pushing.
Write commit message according to the format detailed in my Custom Instructional Rules for AI.
git push -u origin master at last, as `master` is the branch.

Great! Based on your input, we will create a simple Python script that prints the current date and time in a financial time series format.

  1. Navigate to the Local Folder: Open your terminal and navigate to your local folder:
cd /Users/terryli/demo_cursor
  1. Initialize the Git Repository: Initialize the folder as a Git repository:
git init
  1. Create the demo.py File: Create a new Python file named demo.py:
touch demo.py
  1. Edit the demo.py File: Open demo.py in your preferred text editor (Cursor app) and add the following code:
demo.py
from datetime import datetime
# Get current date and time
current_time = datetime.now()
# Format in financial time series format
formatted_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
# Print the formatted time
print(formatted_time)
  1. Test Your SSH Connection to GitHub: Run the following command to test your SSH connection:
ssh -T git@github.com
  1. Add the Remote Repository: Add the remote repository you created:
git remote add origin git@github.com:terrylica/demo_cursor_v1.git
  1. Stage Your Changes: Stage the demo.py file for commit:
git add demo.py
  1. Commit Your Changes: Use the following commit message format:
git commit -m "feat: Add demo script to print current date and time in financial format EI-1009
- Created a simple Python script to demonstrate the capabilities of the Cursor app.
- The script prints the current date and time formatted for financial time series.
Summary: This commit introduces a demo script that outputs the current date and time in a format suitable for financial applications.
Committed File(s): demo.py
Branch: master
Reviewed-by: Terry Li
Refs: EI-1009"
  1. Push Your Changes to GitHub: Finally, push your changes to the remote repository:
git push -u origin master

This will create a basic Python script that demonstrates the capabilities of the Cursor app by printing the current date and time in a financial format. Let me know if you need any further assistance!