77$Pkg = ' MertCapkin_GraphStack[graphify]'
88$GitSpec = ' MertCapkin_GraphStack[graphify] @ git+https://github.com/MertCapkin/GraphStack.git'
99
10- # Do not use Stop — pip/graphify write to stderr and Cursor marks the terminal failed.
1110$ErrorActionPreference = ' Continue'
1211
1312function Resolve-Python {
@@ -23,38 +22,64 @@ function Resolve-Python {
2322}
2423
2524function Invoke-GraphstackPython {
26- param ([string []]$CodeArgs )
27- & $python.Exe @ ($python.PreArgs ) @CodeArgs
28- return $LASTEXITCODE
25+ param (
26+ [string []]$CodeArgs ,
27+ [switch ]$Quiet
28+ )
29+ if ($Quiet ) {
30+ & $python.Exe @ ($python.PreArgs ) @CodeArgs * > $null
31+ } else {
32+ # Out-Host prevents pip stdout from polluting the function return value ($rc = ...).
33+ & $python.Exe @ ($python.PreArgs ) @CodeArgs | Out-Host
34+ }
35+ if ($null -eq $LASTEXITCODE ) { return 0 }
36+ return [int ]$LASTEXITCODE
2937}
3038
3139function Test-WheelAssets {
32- $rc = Invoke-GraphstackPython @ (
40+ $rc = Invoke-GraphstackPython - Quiet @ (
3341 ' -c' ,
3442 " from graphstack.installer import install_source_root; p=install_source_root()/'.cursor'/'rules'/'graphstack.mdc'; import sys; sys.exit(0 if p.is_file() else 1)"
3543 )
3644 return $rc -eq 0
3745}
3846
47+ function Test-GraphstackCli {
48+ $rc = Invoke-GraphstackPython - Quiet @ (' -m' , ' graphstack' , ' --version' )
49+ return $rc -eq 0
50+ }
51+
3952function Install-GraphstackPackage {
40- Write-Host " Step 1/2: Installing MertCapkin_GraphStack + graphify from PyPI..."
41- $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' --force-reinstall' , $Pkg )
53+ if ((Test-GraphstackCli ) -and (Test-WheelAssets )) {
54+ $ver = (& $python.Exe @ ($python.PreArgs ) - m graphstack -- version 2> $null )
55+ Write-Host " Step 1/2: GraphStack already installed ($ver ) — skipping pip."
56+ return
57+ }
58+
59+ Write-Host ' Step 1/2: Installing MertCapkin_GraphStack + graphify from PyPI...'
60+ $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , $Pkg )
4261 if ($rc -ne 0 ) {
4362 Write-Host ' PyPI install failed — trying GitHub source...' - ForegroundColor Yellow
44- $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' --force-reinstall ' , $GitSpec )
63+ $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , $GitSpec )
4564 if ($rc -ne 0 ) {
4665 Write-Error ' Could not install graphstack. Check network and Python pip.'
4766 exit 1
4867 }
4968 }
69+
5070 if (-not (Test-WheelAssets )) {
51- Write-Host ' PyPI wheel missing .cursor assets — installing from GitHub ...' - ForegroundColor Yellow
52- $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' --force-reinstall' , $GitSpec )
71+ Write-Host ' PyPI wheel missing .cursor assets — reinstalling from PyPI ...' - ForegroundColor Yellow
72+ $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' --force-reinstall' , $Pkg )
5373 if ($rc -ne 0 -or -not (Test-WheelAssets )) {
54- Write-Error ' Installed package is missing Cursor workflow files. Open an issue on GitHub.'
55- exit 1
74+ Write-Host ' Trying GitHub source...' - ForegroundColor Yellow
75+ $rc = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' --force-reinstall' , $GitSpec )
76+ if ($rc -ne 0 -or -not (Test-WheelAssets )) {
77+ Write-Error ' Installed package is missing Cursor workflow files. Open an issue on GitHub.'
78+ exit 1
79+ }
5680 }
5781 }
82+
5883 $ver = (& $python.Exe @ ($python.PreArgs ) - m graphstack -- version 2> $null )
5984 Write-Host " Installed: $ver "
6085}
@@ -70,19 +95,26 @@ Write-Host 'GraphStack bootstrap' -ForegroundColor Cyan
7095Write-Host ' ===================='
7196Write-Host ' '
7297
73- $null = Invoke-GraphstackPython @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' pip' , ' --quiet' )
98+ $null = Invoke-GraphstackPython - Quiet @ (' -m' , ' pip' , ' install' , ' --upgrade' , ' pip' )
99+
100+ $ruleFile = Join-Path (Get-Location ) ' .cursor\rules\graphstack.mdc'
101+ if ((Test-GraphstackCli ) -and (Test-WheelAssets ) -and (Test-Path - LiteralPath $ruleFile )) {
102+ Write-Host ' GraphStack is already set up in this project.' - ForegroundColor Green
103+ Write-Host " Rules: $ruleFile "
104+ Write-Host ' Health: py -3 -m graphstack doctor'
105+ exit 0
106+ }
74107
75108Install-GraphstackPackage
76109
77110Write-Host ' '
78111Write-Host ' Step 2/2: Initializing GraphStack in this project...'
79112$initRc = Invoke-GraphstackPython @ (' -m' , ' graphstack' , ' init' , ' .' , ' -y' , ' --install-deps' )
80113
81- $ruleFile = Join-Path (Get-Location ) ' .cursor\rules\graphstack.mdc'
82114if (-not (Test-Path - LiteralPath $ruleFile )) {
83115 Write-Host ' '
84116 Write-Host ' Bootstrap failed: .cursor/rules/graphstack.mdc was not created.' - ForegroundColor Red
85- Write-Host ' Run: py -3 -m pip install -U --force-reinstall '' MertCapkin_GraphStack[graphify]'' '
117+ Write-Host ' Run: py -3 -m pip install -U '' MertCapkin_GraphStack[graphify]'' '
86118 Write-Host ' Then: py -3 -m graphstack init . -y --install-deps'
87119 exit 1
88120}
@@ -91,7 +123,6 @@ if ($initRc -ne 0) {
91123 Write-Host ' '
92124 Write-Host " Init reported issues (exit $initRc ) but core files are present." - ForegroundColor Yellow
93125 Write-Host ' Run: py -3 -m graphstack doctor'
94- exit 0
95126}
96127
97128Write-Host ' '
0 commit comments