Several issues going on here; cursor is an OS-ist (racist against OSs) – it truly loves to be mac native
So you have to constantly remind it that on windows - to invoke all things via powershell commands it will constantly attempt to chain commands with &&…
(FIX THIS BEHAVIOR @anon-9002714 – Have the ■■■■ IDE do an OS check EVERY time it launches to know what terminal lexicon to use)
–
Second, please take my advice and tell it to only wrap all terminal commands in a .ps1 that it then executes and to store all the .ps1s in your projects /@scripts/ folder… and direct it to provide a max 200 char description of the command…
THis allows you to have atomic file history of all terminal invocations the bot does… (invocation is my word of the day, kids)…
It appears that when cursor f-ups the CLI and tries && on powershell, it will loop back to “let me try that another way” many times… and this churns through its context window allotment.
–
If you see a composer ‘generating…’ for long periods, just type ‘continue’ or ‘?’ and it will give it a nudge to regroup…
Sometimes you’ll need to just create a new session - which can be super problematic if your context training took a significant effort (which ■■■■ but will fade in time)
title: “Cursor AI PowerShell Directives”
subtitle: “Script Management and Execution Guidelines”
author: “Cursor AI”
date: “r format(Sys.time(), '%B %d, %Y')
”
output:
html_document:
toc: true
theme: united
highlight: tango
PowerShell Script Management Directive
Core Principle
All terminal operations should be encapsulated in PowerShell scripts (.ps1) stored in the scripts/
directory. Direct terminal execution should be avoided in favor of documented, reusable scripts.
Implementation Rules
-
Script Location
- All PowerShell scripts must be stored in
scripts/
- Use subdirectories for organization (e.g.,
scripts/setup/
, scripts/maintenance/
)
- Maintain consistent naming:
verb-noun.ps1
-
Documentation Requirements
- Header block with purpose, parameters, and examples
- Inline comments for complex operations
- README.md in script directories
- Version history in script headers
-
Script Structure
<#
.SYNOPSIS
Brief description
.DESCRIPTION
Detailed description
.PARAMETER ParamName
Parameter description
.EXAMPLE
Usage example
.NOTES
Version: 1.0
Author: Cursor AI
Last Updated: Date
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$ParamName
)
-
Execution Model
- Scripts should be parameterized
- Use error handling and logging
- Return structured output
- Support -WhatIf operations
Example Implementation
Directory Structure
scripts/
├── setup/
│ ├── install-dependencies.ps1
│ └── configure-environment.ps1
├── maintenance/
│ ├── backup-database.ps1
│ └── cleanup-logs.ps1
└── README.md
Script Template
<#
.SYNOPSIS
Template for new PowerShell scripts
.DESCRIPTION
Provides a standardized structure for all new PowerShell scripts
in the project, ensuring consistency and maintainability.
.PARAMETER Operation
The operation to perform
.EXAMPLE
./template-script.ps1 -Operation "test"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$Operation
)
# Script initialization
$ErrorActionPreference = "Stop"
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$RootPath = Split-Path -Parent $ScriptPath
# Import common functions
. "$ScriptPath\common\functions.ps1"
# Main operation
try {
Write-Host "Executing $Operation..."
# Operation logic here
}
catch {
Write-Error "Operation failed: $_"
exit 1
}
Execution Guidelines
-
Instead of Direct Execution:
# DON'T: Execute directly
psql -U postgres -c "CREATE DATABASE mydb"
# DO: Create and use a script
./scripts/setup/create-database.ps1 -Name "mydb"
-
Error Handling:
# In scripts/setup/create-database.ps1
try {
$result = & psql -U postgres -c "CREATE DATABASE $Name"
Write-Host "Database created successfully"
}
catch {
Write-Error "Failed to create database: $_"
exit 1
}
Documentation Example
Script Header
<#
.SYNOPSIS
Creates a new PostgreSQL database
.DESCRIPTION
Creates a new PostgreSQL database with the specified name
and configures basic settings. Supports error handling and
logging.
.PARAMETER Name
The name of the database to create
.PARAMETER Owner
Optional. The owner of the database
.EXAMPLE
./create-database.ps1 -Name "myapp_db"
.EXAMPLE
./create-database.ps1 -Name "myapp_db" -Owner "appuser"
.NOTES
Version: 1.0
Author: Cursor AI
Last Updated: 2024-01-02
#>
Best Practices
-
Version Control
- Include version numbers in script headers
- Document changes in script history
- Use semantic versioning
-
Testing
- Include test cases in script documentation
- Support -WhatIf parameter for dry runs
- Validate parameters
-
Maintenance
- Regular script audits
- Update documentation
- Remove deprecated scripts
-
Security
- No hardcoded credentials
- Use secure parameter types
- Implement proper permissions
Integration with Cursor AI
-
Script Generation
- Use templates for consistency
- Auto-generate documentation
- Validate script structure
-
Execution Context
- Scripts should be workspace-aware
- Support multiple environments
- Handle Cursor AI specific paths
-
Logging
- Write to Cursor AI log directory
- Use structured logging
- Support different log levels