Skip to content

Conversation

@AliSoftware
Copy link
Contributor

@AliSoftware AliSoftware commented Feb 20, 2025

What

As per my suggestion in paaHJt-7WG-p2#comment-10141, this is the result of me asking Cursor to add .cursorrules for PowerShell in addition to the ones I recently added for bash

How

I used the following prompts to ask Cursor to generate those rules itself:

You are an expert in PowerShell and Bash scripting.
Looking at the PowerShell .ps1 scripts we have in @bin , and accounting for the current @.cursorrules we have for bash scripts, suggest additional rules to @.cursorrules that would be useful to you (Cursor and the LLM) to help apply similar good standards and guidelines for .ps1 scripts.

It then generated some rules, but including mentions of ensuring the .ps1 scripts would be Cross-Platform for Windows, Linux and macOS—based on us having a similar set of Compatibilty rules for bash, I assume… So I asked it to refine its suggestion:

We will only write .ps1 PowerShell scripts for Windows systems, so you can remove all the considerations and instructions about those being Cross-Platform

It then updated its suggestions to the ones I've pushed in cbf4991.

I then added some manual tweaks to the .cursorrules file in 7766406 and e9c04a2.

[EDIT] After all that I then moved the markdown section to separate .cursor/rules/*.mdc files (instead of having them all in a single .cursorrules), since that seems to be the new suggested format to use for those in latest Cursor versions.

@dangermattic
Copy link

dangermattic commented Feb 20, 2025

1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Generated by 🚫 Danger

@AliSoftware AliSoftware requested review from a team and mokagio February 20, 2025 10:42
@AliSoftware
Copy link
Contributor Author

AliSoftware commented Feb 20, 2025

Note: we should probably switch to use .cursor/rules/NN-name.mdc files instead of a unique .cursorrules file at that point.

Though:

[EDIT] Conversion to .mdc files done in aeffa77.
I've indeed encountered the bug mentioned in cursor/cursor#2683 when asking Cursor to generate those .mdc files for me from the .cursorrules file, so I had to create them manually instead, and quite and restart Cursor. But then after prompting it with Can you help me improve @cache_cocoapods_specs_repos based on your @rules ? its answer suggested it correctly accounted for the rules written in the new .mdc format (suggested to use [[ … ]], added documentation, …), which seems to confirm the converted rules would still work as expected 👍

@AliSoftware AliSoftware marked this pull request as ready for review February 20, 2025 13:51
@AliSoftware
Copy link
Contributor Author

I've created a draft PR #157 on top of this to check/demo how well those rules could help us use Cursor to improve our scripts and their documentation.

Copy link
Contributor

@mokagio mokagio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AliSoftware !

Cursor rules are new to me, so I don't know how effective these would be. But I like how they are tracked in the repo so we can iterate 😄

Happy to merge and try them out.

Comment on lines +55 to +87
```powershell
<#
.SYNOPSIS
Brief description of what the script does.

.DESCRIPTION
Detailed description of the script's purpose and functionality.

.PARAMETER ParameterName
Description of each parameter.

.EXAMPLE
Example-1
Detailed description of the example.

.NOTES
Author: [Author name]
Last Edit: [Date]
Version 1.0 - Initial release
Requirements: Windows PowerShell 5.1
Windows Requirements:
- Windows Server 2019 or later
- Required Windows Features: [list features]
- Required Windows Roles: [list roles]
- Administrator privileges: [Yes/No]

.OUTPUTS
Description of the script's output.

.RETURNVALUES
Description of possible return values and their meanings.
#>
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc format is huge

Copy link
Contributor Author

@AliSoftware AliSoftware Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed.

But I'd encorage you to test it by asking Cursor to Add documentation header in @bin/prepare_windows_host_for_app_distribution.ps1 as a prompt—which should make it detect that this file has the .ps1 extension so that it should pick the @rules for it automatically—and see what it generates.

In particular I believe it'd be smart enough to only add the sections of this documentation template that are relevant and used (e.g. not include .EXAMPLE if it doesn't have any to provide, same for .PARAMETER entries…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: You might have to quit Cursor before switching to the git branch that have this .mdc files and restarting Cursor, as based on this bug report it seems that the files are parsed at Cursor launch (and the cursor executable has an open file handle on them from that point on…), so changes in the .mdc files might not be taken into account until you quit and restart the IDE…?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got Cursor to generate docs in #159

@AliSoftware AliSoftware merged commit cc6f208 into trunk Feb 20, 2025
18 checks passed
@AliSoftware AliSoftware deleted the cursor-rules-powershell branch February 20, 2025 20:27
mokagio pushed a commit that referenced this pull request Feb 21, 2025
* Add Cursor rules for PowerShell scripts

* Suggest Cursor to create a PowerShell script counterpart to bash scripts if it's not possible to make an original bash script compatible with Windows

* Add more context at the top of `.cursorrules`

* Migrate `.cursorrules` to `.cursor/rules/*.mdc`

* Add rule for using backticks around command names

* Add missing newline at EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants