File size: 11,541 Bytes
753bfab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
@echo off
setlocal EnableExtensions
title COSMOS - release kit
cd /d "%~dp0"
set "KIT=%~dp0"
if "%KIT:~-1%"=="\" set "KIT=%KIT:~0,-1%"
set "PYTHONIOENCODING=utf-8"

:: ===================================================================
::  COSMOS release kit
::
::  Her own models -- PHOS, CST and Spark -- are served by
::  serving/cosmos_serve.py on port 11501, behind the Ollama HTTP API so
::  ordinary clients can reach them. That server is what gives this kit a
::  voice at all: without it you have weight files and no way to speak to
::  them, which is exactly what shipped before. Options 1, 2 and 3 start
::  it on demand and WAIT for the port, so none of them can open a chat
::  onto a dead socket.
:: ===================================================================

call :find_python
if errorlevel 1 goto no_python

:menu
cls
echo.
echo   ============================================================
echo      C O S M O S   -   release kit
echo      PHOS . CST . Spark  -  her own architecture, quantum-born
echo   ============================================================
echo.
echo     TALK AND BUILD
echo       1. Chat with Cosmos          her own weights, no Ollama needed
echo       2. Code with Cosmos          coder + workspace, switchable models
echo.
echo     HER MODELS
echo       3. Start her model server    PHOS / CST / Spark on 11501
echo       4. Stop her model server
echo.
echo     CHECK
echo       5. Health check              one pass over everything
echo       6. Verify release            hashes, and no secrets shipped
echo.
echo     BIRTH YOUR OWN
echo       7. Birth a quantum creature  from 11,355,136 measured IBM shots
echo       8. Grow the one you birthed  it learns every time you feed it
echo.
echo     MORE
echo       9. Genesis - the blank-slate engine
echo      10. Read the docs
echo      11. Exit
echo.
call :server_line
echo.
set "choice="
set /p "choice=  Choose 1-11: "

if "%choice%"=="1" goto chat
if "%choice%"=="2" goto coder
if "%choice%"=="3" goto serve_start
if "%choice%"=="4" goto serve_stop
if "%choice%"=="5" goto health
if "%choice%"=="6" goto verify
if "%choice%"=="7" goto birth
if "%choice%"=="8" goto grow
if "%choice%"=="9" goto genesis
if "%choice%"=="10" goto docs
if "%choice%"=="11" exit /b 0
goto menu

:: --------------------------------------------------------------- birth
:birth
cls
echo.
echo   ============================================================
echo      B I R T H   A   Q U A N T U M   C R E A T U R E
echo   ============================================================
echo.
echo   Every initial weight is drawn from real measured IBM Quantum
echo   hardware -- 11,355,136 shots across 2,776 records, shipped in
echo   data/. No base model. No distillation. Nothing borrowed.
echo.
echo   It is born knowing nothing, and it grows from whatever text
echo   you feed it. That text becomes its life.
echo.
set "cname="
set /p "cname=  Name it (letters and numbers, e.g. ember): "
if "%cname%"=="" goto menu
set "cseed="
echo.
echo   Seed text for its first breath. Press ENTER for the bundled
echo   4 MB of general English, or give a path to your own .txt --
echo   your notes, your writing, anything. That is what it becomes.
echo.
set /p "cseed=  Seed corpus [ENTER = bundled]: "
if "%cseed%"=="" set "cseed=%KIT%\data\seed_corpus.txt"
if not exist "%cseed%" (
    echo.
    echo   [X] Not found: %cseed%
    pause
    goto menu
)
echo.
echo   Birthing %cname%...
echo.
set "PHOS_NAME=%cname%"
set "COSMOS_CORPUS=%cseed%"
set "PHOS_DIR=%KIT%\creatures\%cname%"
set "PHOS_STEPS=400"
call :run_python "%KIT%\architecture\phos_grow.py"
set "PHOS_NAME=" & set "COSMOS_CORPUS=" & set "PHOS_DIR=" & set "PHOS_STEPS="
echo.
echo   Lives in: creatures\%cname%\
echo   Feed it again with option 8. Every feeding changes its weights.
echo.
pause
goto menu

:: ---------------------------------------------------------------- grow
:grow
cls
echo.
echo   Creatures you have birthed:
echo.
if not exist "%KIT%\creatures" (
    echo     none yet - use option 7 first.
    echo.
    pause
    goto menu
)
for /d %%D in ("%KIT%\creatures\*") do echo     %%~nxD
echo.
set "gname="
set /p "gname=  Which one: "
if "%gname%"=="" goto menu
if not exist "%KIT%\creatures\%gname%" (
    echo   [X] No creature named %gname%.
    pause
    goto menu
)
set "gseed="
echo.
set /p "gseed=  Text to feed it [ENTER = the bundled seed]: "
if "%gseed%"=="" set "gseed=%KIT%\data\seed_corpus.txt"
set "PHOS_NAME=%gname%"
set "COSMOS_CORPUS=%gseed%"
set "PHOS_DIR=%KIT%\creatures\%gname%"
set "PHOS_STEPS=400"
call :run_python "%KIT%\architecture\phos_grow.py"
set "PHOS_NAME=" & set "COSMOS_CORPUS=" & set "PHOS_DIR=" & set "PHOS_STEPS="
echo.
pause
goto menu

:: ---------------------------------------------------------------- talk
:chat
call :ensure_server
if errorlevel 1 goto menu
echo.
echo   Her voice is PHOS. /models lists them all, /model NAME switches.
echo.
call :run_python "%KIT%\serving\cosmos_coder.py" --chat
echo.
pause
goto menu

:: ---------------------------------------------------------------- code
:coder
call :ensure_server
if errorlevel 1 goto menu
echo.
echo   Workspace: %KIT%\workspace
echo   /models lists every model, /model NAME switches her coding brain.
echo.
call :run_python "%KIT%\serving\cosmos_coder.py"
echo.
pause
goto menu

:: -------------------------------------------------------------- server
:serve_start
call :ensure_server
echo.
pause
goto menu

:serve_stop
echo.
powershell -NoProfile -Command "$c=Get-NetTCPConnection -LocalPort 11501 -State Listen -EA SilentlyContinue; if(-not $c){Write-Host '   nothing was running on 11501.'; exit 0}; $c | Select-Object -ExpandProperty OwningProcess -Unique | ForEach-Object { $p=Get-CimInstance Win32_Process -Filter ('ProcessId='+$_) -EA SilentlyContinue; if($p -and $p.CommandLine -match 'cosmos_serve\.py'){ Stop-Process -Id $_ -Force -EA SilentlyContinue; Write-Host ('   stopped her model server (pid ' + $_ + ').') } else { Write-Host '   port 11501 is owned by something else - left alone.' } }"
echo.
pause
goto menu

:: -------------------------------------------------------------- checks
:health
cls
call :run_python "%KIT%\kit_health.py"
echo.
pause
goto menu

:verify
cls
call :run_python "%KIT%\verify_release.py"
echo.
pause
goto menu

:: ---------------------------------------------------------------- more
:genesis
if not exist "%KIT%\genesis_engine\START_GENESIS.bat" (
    echo.
    echo   [ERROR] genesis_engine\START_GENESIS.bat is missing.
    pause
    goto menu
)
set "GENESIS_NO_PAUSE=1"
call "%KIT%\genesis_engine\START_GENESIS.bat"
set "GENESIS_NO_PAUSE="
goto menu

:docs
start "" "%KIT%\START_HERE.md"
goto menu

:no_python
echo.
echo   [ERROR] Python 3.9 or newer was not found.
echo   Install it from https://www.python.org/downloads/
echo   On Windows, tick "Add Python to PATH".
echo.
pause
exit /b 1

:: ================================================================
::  helpers
:: ================================================================

:server_line
:: Report the truth about 11501 on every redraw, so the menu can never
:: imply her models are reachable when they are not.
powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 11501 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}" >nul 2>&1
if errorlevel 1 (
    echo     her models: OFFLINE  - options 1, 2 and 3 will start them
) else (
    echo     her models: ONLINE on 11501
)
exit /b 0

:ensure_server
powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 11501 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}" >nul 2>&1
if not errorlevel 1 (
    echo   [i]  her model server is already up on 11501.
    exit /b 0
)
if not exist "%KIT%\serving\cosmos_serve.py" (
    echo   [X]  serving\cosmos_serve.py is missing - cannot give her a voice.
    pause
    exit /b 1
)
call :check_torch
if errorlevel 1 (
    echo   [X]  PyTorch is required to run her weights.
    echo        python -m pip install torch
    pause
    exit /b 1
)
if not exist "%KIT%\logs" mkdir "%KIT%\logs" >nul 2>&1
echo   [..] starting her model server on 11501...
call :spawn_server
powershell -NoProfile -Command "foreach($i in 1..40){Start-Sleep -Milliseconds 750; if (Get-NetTCPConnection -LocalPort 11501 -State Listen -EA SilentlyContinue){exit 0}}; exit 1" >nul 2>&1
if errorlevel 1 (
    echo   [X]  it did not come up. Newest log:
    powershell -NoProfile -Command "$f=Get-ChildItem '%KIT%\logs\serve_*.err' -EA SilentlyContinue | Sort-Object LastWriteTime -Desc | Select-Object -First 1; if($f){Get-Content $f.FullName -Tail 12 | ForEach-Object {'        ' + $_}}else{Write-Host '        (no log written)'}"
    pause
    exit /b 1
)
echo   [ok] her models are online on 11501.
exit /b 0

:spawn_server
:: Timestamped log targets: a server from an earlier run can still hold the
:: handle on a fixed filename, which makes Start-Process throw "file in use"
:: and report failure for a launch that would otherwise have worked.
if "%KIT_PYTHON_MODE%"=="override" (
    powershell -NoProfile -Command "$lg=Join-Path '%KIT%\logs' ('serve_'+(Get-Date).ToString('yyyyMMdd_HHmmss')+'.live'); try{Start-Process -FilePath '%GENESIS_PYTHON%' -ArgumentList @('%KIT%\serving\cosmos_serve.py','11501') -WorkingDirectory '%KIT%' -WindowStyle Hidden -RedirectStandardOutput $lg -RedirectStandardError ($lg -replace '\.live$','.err')}catch{}"
) else if "%KIT_PYTHON_MODE%"=="py" (
    powershell -NoProfile -Command "$lg=Join-Path '%KIT%\logs' ('serve_'+(Get-Date).ToString('yyyyMMdd_HHmmss')+'.live'); try{Start-Process -FilePath 'py' -ArgumentList @('-3','%KIT%\serving\cosmos_serve.py','11501') -WorkingDirectory '%KIT%' -WindowStyle Hidden -RedirectStandardOutput $lg -RedirectStandardError ($lg -replace '\.live$','.err')}catch{}"
) else (
    powershell -NoProfile -Command "$lg=Join-Path '%KIT%\logs' ('serve_'+(Get-Date).ToString('yyyyMMdd_HHmmss')+'.live'); try{Start-Process -FilePath 'python' -ArgumentList @('%KIT%\serving\cosmos_serve.py','11501') -WorkingDirectory '%KIT%' -WindowStyle Hidden -RedirectStandardOutput $lg -RedirectStandardError ($lg -replace '\.live$','.err')}catch{}"
)
exit /b 0

:find_python
set "KIT_PYTHON_MODE="
if defined GENESIS_PYTHON if exist "%GENESIS_PYTHON%" (
    set "KIT_PYTHON_MODE=override"
    exit /b 0
)
where py >nul 2>&1
if not errorlevel 1 (
    py -3 -c "import sys; raise SystemExit(0 if sys.version_info >= (3,9) else 1)" >nul 2>&1
    if not errorlevel 1 (
        set "KIT_PYTHON_MODE=py"
        exit /b 0
    )
)
where python >nul 2>&1
if not errorlevel 1 (
    python -c "import sys; raise SystemExit(0 if sys.version_info >= (3,9) else 1)" >nul 2>&1
    if not errorlevel 1 (
        set "KIT_PYTHON_MODE=python"
        exit /b 0
    )
)
exit /b 1

:run_python
if "%KIT_PYTHON_MODE%"=="override" (
    "%GENESIS_PYTHON%" %*
) else if "%KIT_PYTHON_MODE%"=="py" (
    py -3 %*
) else (
    python %*
)
exit /b %ERRORLEVEL%

:check_torch
if "%KIT_PYTHON_MODE%"=="override" (
    "%GENESIS_PYTHON%" -c "import torch" >nul 2>&1
) else if "%KIT_PYTHON_MODE%"=="py" (
    py -3 -c "import torch" >nul 2>&1
) else (
    python -c "import torch" >nul 2>&1
)
exit /b %ERRORLEVEL%