-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.ps1
More file actions
98 lines (80 loc) · 3.2 KB
/
Copy pathinit.ps1
File metadata and controls
98 lines (80 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#Requires -Version 5.1
<#
.SYNOPSIS
Initialize a project with cursor-prime rules and starter docs.
.DESCRIPTION
Creates the following in the current working directory:
- .cursor\rules\behavior.mdc (always-applied Plan Gate + Karpathy rules)
- .cursor\rules\project.mdc (project context, agent-requested)
- progress.md (working log)
- .gitignore (project-specific ignores)
- .cursor\hooks\* (optional; -WithHooks)
This is the most reliable way to make the Plan Gate apply, because Cursor
loads .cursor/rules/*.mdc from the open project workspace.
Existing files are never overwritten unless -Force is passed (in which case
they are backed up to .bak.<timestamp>).
.PARAMETER Force
Overwrite existing files; back them up first.
.PARAMETER WithHooks
Install optional project hooks (.cursor/hooks.json) that ask before
destructive shell commands. Default: off.
.EXAMPLE
cd path\to\my\project
& "$env:USERPROFILE\cursor-prime\init.ps1"
.EXAMPLE
& "$env:USERPROFILE\cursor-prime\init.ps1" -Force -WithHooks
#>
[CmdletBinding()]
param(
[switch]$Force,
[switch]$WithHooks
)
$ErrorActionPreference = 'Stop'
$Repo = $PSScriptRoot
$Target = (Get-Location).Path
$Timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
function Log ($m) { Write-Host "[cursor-prime init] $m" -ForegroundColor Cyan }
function Skip ($m) { Write-Host "[cursor-prime init] $m" -ForegroundColor DarkGray }
# (template-name-in-repo, target-path-relative-to-cwd) pairs.
$Files = @(
@{ Src = 'behavior.mdc'; Dst = '.cursor\rules\behavior.mdc' }
@{ Src = 'project.mdc'; Dst = '.cursor\rules\project.mdc' }
@{ Src = 'progress.md'; Dst = 'progress.md' }
@{ Src = 'gitignore'; Dst = '.gitignore' }
)
if ($WithHooks) {
$Files += @{ Src = 'hooks\hooks.json'; Dst = '.cursor\hooks\hooks.json' }
$Files += @{ Src = 'hooks\guard-destructive.ps1'; Dst = '.cursor\hooks\guard-destructive.ps1' }
}
# Validate sources before touching anything
foreach ($f in $Files) {
$src = Join-Path $Repo "templates\$($f.Src)"
if (-not (Test-Path $src)) { throw "Template missing: $src" }
}
foreach ($f in $Files) {
$src = Join-Path $Repo "templates\$($f.Src)"
$dstAbs = Join-Path $Target $f.Dst
$dstDir = Split-Path $dstAbs -Parent
if (-not (Test-Path $dstDir)) {
New-Item -ItemType Directory -Force -Path $dstDir | Out-Null
}
if (Test-Path $dstAbs) {
if ($Force) {
$backup = "$dstAbs.bak.$Timestamp"
Copy-Item $dstAbs $backup -Force
Copy-Item $src $dstAbs -Force
Log "Replaced: $($f.Dst) (backup: $(Split-Path $backup -Leaf))"
} else {
Skip "Skipped (exists): $($f.Dst)"
}
} else {
Copy-Item $src $dstAbs -Force
Log "Created: $($f.Dst)"
}
}
if ($WithHooks) {
Log "Project hooks installed (.cursor/hooks.json). Restart Cursor if hooks do not load immediately."
} else {
Skip "Hooks not installed (default). Re-run with -WithHooks to add destructive-command guard."
}
Log "Done. Open a new Cursor chat here and ask for a non-trivial task to verify Plan Gate."