Repository navigation
Expand file tree
/
Copy pathbootstrap_dev.ps1
More file actions
249 lines (216 loc) · 5.94 KB
/
Copy pathbootstrap_dev.ps1
File metadata and controls
249 lines (216 loc) · 5.94 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# scripts\bootstrap_dev.ps1 - fresh-machine dev bootstrap (renamed from the
# repo-root bootstrap script 2026-10-09, MAIN 2246 sec 3). Default -Root is the
# repo root: this file's parent folder.
param(
[string]$Root = (Split-Path -Parent $PSScriptRoot)
)
$ErrorActionPreference = "Stop"
function Write-Step([string]$Message) {
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Ensure-Dir([string]$Path) {
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -ItemType Directory -Force -Path $Path | Out-Null
}
}
function Install-WingetPackage([string]$Id) {
Write-Step "Installing or upgrading $Id"
winget install --id $Id -e --source winget --silent --accept-package-agreements --accept-source-agreements
if ($LASTEXITCODE -ne 0) {
throw "winget failed for $Id (exit $LASTEXITCODE)"
}
}
function Find-Git() {
$cmd = Get-Command git.exe -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
$candidates = @(
"C:\Program Files\Git\cmd\git.exe",
"C:\Program Files\Git\bin\git.exe",
"C:\Program Files (x86)\Git\cmd\git.exe",
"C:\Program Files (x86)\Git\bin\git.exe"
)
foreach ($candidate in $candidates) {
if (Test-Path $candidate) { return $candidate }
}
return $null
}
if (-not (Test-Path -LiteralPath $Root)) {
throw "Project root not found: $Root"
}
Write-Step "Installing core Windows tools"
$packages = @(
"Git.Git",
"Microsoft.PowerShell",
"astral-sh.uv",
"BurntSushi.ripgrep.MSVC",
"jqlang.jq"
)
foreach ($pkg in $packages) {
Install-WingetPackage $pkg
}
Write-Step "Creating Python virtual environment"
$venv = Join-Path $Root ".venv"
if (-not (Test-Path -LiteralPath $venv)) {
& py -3.14 -m venv $venv
if ($LASTEXITCODE -ne 0) {
throw "Failed to create venv with py -3.14. Install Python 3.14 or adjust the script."
}
}
$python = Join-Path $venv "Scripts\python.exe"
$pip = @(
"-m", "pip", "install", "--upgrade",
"pip",
"wheel",
"anthropic",
"httpx",
"orjson",
"tenacity",
"psutil",
"pywin32",
"mss",
"watchfiles",
"pydantic-settings",
"ruff"
)
Write-Step "Installing Python packages into .venv"
& $python $pip
if ($LASTEXITCODE -ne 0) {
throw "pip install failed"
}
$pywinPost = Join-Path (Split-Path $python -Parent) "pywin32_postinstall.py"
if (Test-Path $pywinPost) {
Write-Step "Running pywin32 post-install"
& $python $pywinPost -install
}
Write-Step "Creating project directories"
$dirs = @(
"ops",
"ops\staging",
"ops\backups",
"ops\runtime",
"ops\runtime\deploy_requests",
"ops\runtime\deploy_results",
"ops\runtime\health",
"tools"
)
foreach ($dir in $dirs) {
Ensure-Dir (Join-Path $Root $dir)
}
Write-Step "Writing requirements-dev.txt"
@'
anthropic
httpx
orjson
tenacity
psutil
pywin32
mss
watchfiles
pydantic-settings
ruff
'@ | Set-Content -LiteralPath (Join-Path $Root "requirements-dev.txt") -Encoding UTF8
Write-Step "Writing ruff.toml"
@'
target-version = "py39"
line-length = 100
[lint]
select = ["E", "F", "I", "UP", "B"]
ignore = ["E501"]
[format]
quote-style = "double"
indent-style = "space"
line-ending = "lf"
'@ | Set-Content -LiteralPath (Join-Path $Root "ruff.toml") -Encoding UTF8
Write-Step "Writing .gitignore"
@'
# Secrets
API-Key-Claude.txt
.env
.env.*
*.secret
*.secrets.json
# Python
.venv/
__pycache__/
*.pyc
*.pyo
*.pyd
# Logs and temp
logs/
*.log
restart_trigger.txt
apply_patches.py
# Runtime state
ops/runtime/health/
ops/runtime/deploy_results/
data/coaching_data.json
data/tft_coaching_data.json
data/tft_live_data.json
data/comp_state.json
data/ratings/
data/match_history.db
# Build / cache
.pytest_cache/
.ruff_cache/
.mypy_cache/
'@ | Set-Content -LiteralPath (Join-Path $Root ".gitignore") -Encoding UTF8
Write-Step "Writing tools\\preflight.cmd"
@'
@echo off
setlocal
cd /d "%~dp0.."
.\.venv\Scripts\ruff.exe check .
if errorlevel 1 exit /b 1
.\.venv\Scripts\python.exe -m compileall -q .
if errorlevel 1 exit /b 1
echo PRECHECK OK
'@ | Set-Content -LiteralPath (Join-Path $Root "tools\preflight.cmd") -Encoding ASCII
Write-Step "Writing tools\\snapshot.cmd"
@'
@echo off
setlocal
cd /d "%~dp0.."
for /f %%I in ('powershell -NoProfile -Command "Get-Date -Format yyyy-MM-dd_HH-mm-ss"') do set TS=%%I
git add -A
git commit --allow-empty -m "checkpoint %TS%"
'@ | Set-Content -LiteralPath (Join-Path $Root "tools\snapshot.cmd") -Encoding ASCII
Write-Step "Writing tools\\rollback_last.cmd"
@'
@echo off
setlocal
cd /d "%~dp0.."
git reset --hard HEAD~1
'@ | Set-Content -LiteralPath (Join-Path $Root "tools\rollback_last.cmd") -Encoding ASCII
Write-Step "Initializing git repository"
$git = Find-Git
if (-not $git) {
throw "git.exe not found after installation"
}
& $git config --global core.longpaths true
& $git config --global core.autocrlf false
# FLEET-COMMON 17 (kit v13/v14): every commit carries the OPERATOR identity.
# Never invent a placeholder or bot identity here - a missing one skips the
# checkpoint commit instead, and the operator sets their own.
$userName = (& $git config --global user.name 2>$null)
$userEmail = (& $git config --global user.email 2>$null)
$haveIdentity = ($userName -and $userEmail)
if (-not $haveIdentity) {
Write-Warning "git user.name / user.email are not set. Set the OPERATOR identity with 'git config --global user.name' and 'git config --global user.email', then re-run. The checkpoint commit is skipped."
}
if (-not (Test-Path -LiteralPath (Join-Path $Root ".git"))) {
& $git -C $Root init -b main
}
if ($haveIdentity) {
& $git -C $Root add -A
try {
& $git -C $Root commit --allow-empty -m "checkpoint: baseline dev stack"
} catch {
Write-Host "Initial commit skipped or already up to date." -ForegroundColor Yellow
}
}
Write-Step "Done"
Write-Host ""
Write-Host "Next commands:" -ForegroundColor Green
Write-Host " $Root\tools\preflight.cmd"
Write-Host " $Root\tools\snapshot.cmd"
Write-Host " $Root\tools\rollback_last.cmd"