okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4e6a1b46b
main
1"""Writes the text previews of every `strata launch` screen to docs/terminal-previews/launch-*.txt (fake computer: RTX 5070 12 GB, 64 GB RAM). 2 3python tests/terminal/launch_previews.py 4 5They are what the screens draw at 110 x 34 (the monitor views at 120 x 36), as text, so the design can be read without running anything. 6""" 7 8from __future__import annotations 9 10import asyncio 11import io 12import os 13import sys 14import time 15from pathlib import Path 16from unittest import mock 17 18ROOT = Path (__file__ ).resolve ().parents [2 ] 19sys .path .insert (0 ,str (ROOT )) 20 21from rich .console import Console # noqa: E402 22 23from strata_cli .launch import access ,settings as S ,store # noqa: E402 24from strata_cli .launch .app import Ctx ,LaunchApp # noqa: E402 25from strata_cli .launch .widgets import Glyphs # noqa: E402 26from tests .terminal import test_overview as ov # noqa: E402 27from tests .terminal .launch_support import HW_12 ,HW_2X16 ,Home ,catalog ,text_of # noqa: E402 28 29OUT = ROOT / "docs" / "terminal-previews" 30SIZE = (110 ,34 ) 31 32 33def ctx_for (hw ): 34cat = catalog (hw ) 35comp = cat .computer () 36return Ctx (catalog = cat ,computer = comp ,rows = cat .rows (comp .raw ),settings = S .LaunchSettings (),glyphs = Glyphs (True )) 37 38 39def write (name :str ,text :str ,note :str )-> None : 40body = f"# strata launch preview: { note } \n# (text of the screen as drawn at the size named in tests/terminal/launch_previews.py)\n\n" + text .rstrip ()+ "\n" 41 (OUT / f"launch- { name } .txt" ).write_text (body ,encoding = "utf-8" ) 42"wrote" ,f"launch- { name } .txt" ) 43 44 45async def keys (pilot ,* ks ): 46for k in ks : 47await pilot .press (k ) 48await pilot .pause (0.15 ) 49 50 51def run ()-> None : 52OUT .mkdir (parents = True ,exist_ok = True ) 53with Home (): 54store .save (S .LaunchSettings (name = "IQ3_XXS 128K - Full speed" ,family = "qwen" ,model = "IQ3_XXS" ,context = 131072 ,parallel = 1 , 55tuned_preset = "x" ,tuned_at = "2026-10-16" ,last_used = "2026-10-16 09:00:00" )) 56store .save (S .LaunchSettings (name = "Coder 64K - agents" ,family = "coder" ,model = "IQ1_M" ,context = 65536 ,parallel = 2 ,last_used = "2026-10-14 09:00:00" )) 57store .save (S .LaunchSettings (name = "Network serving" ,family = "qwen" ,model = "Q2_0" ,context = 32768 ,parallel = 1 ,tuned_preset = "y" , 58tuned_at = "2026-10-15" ,last_used = "2026-10-15 09:00:00" )) 59base = {"exe" :"component:strata-engine" ,"args" : ["--max-context" ,"131072" ,"--kv" ,"int8" ,"--prefill" ,"auto" ,"--expert-cache" ,"auto" , 60"--spec" ,"4" ]} 61help_text = (" --max-context N memory for the conversation (default 4096)\n --kv fp16|int8 how the conversation memory is stored\n" 62" --prefill N how many prompt tokens are read at once\n --expert-cache N experts kept in graphics memory\n" 63" --spec N draft tokens per step (faster replies)\n --native-rope experimental pinned rotary arithmetic\n" ) 64patches = [mock .patch .object (Ctx ,"base_config" ,lambda self :base ),mock .patch .object (Ctx ,"engine_exe" ,lambda self :"/engine/strata" ), 65mock .patch ("strata_cli.launch.params.engine_help_text" ,return_value = help_text ), 66mock .patch .object (access ,"lan_ips" ,return_value = ["192.168.88.21" ]), 67mock .patch .object (access ,"find_cloudflared" ,return_value = "/usr/bin/cloudflared" ), 68mock .patch .object (access ,"tailscale_status" ,return_value = {"installed" :False ,"running" :False ,"ip" :None ,"name" :None })] 69for p in patches : 70p .start () 71 72async def tour (hw ,prefix ,steps_after_start ): 73ctx = ctx_for (hw ) 74app = LaunchApp (ctx ) 75async with app .run_test (size = SIZE )as pilot : 76await pilot .pause (0.3 ) 77write (f" { prefix } start" ,text_of (app ),"start screen with saved presets" ) 78for name ,ks in steps_after_start : 79await keys (pilot ,* ks ) 80write (f" { prefix } { name } " ,text_of (app ),name ) 81 82asyncio .run (tour (HW_12 ,"" , [ 83 ("step1-model" , ["down" ,"down" ,"down" ,"enter" ]), 84 ("step2-folder" , ["enter" ]), 85 ("step3-context" , ["enter" ,"down" ,"down" ]), 86 ("step4-pictures" , ["enter" ]), 87 ("step5-parallel" , ["enter" ]), 88 ("step6-tuning" , ["enter" ]), 89 ("step7-advanced" , ["enter" ]), 90 ("step8-access" , ["n" ,"down" ]), 91 ("step9-save" , ["enter" ]), 92 ])) 93asyncio .run (tour (HW_2X16 ,"twocards-" , [("step2-cards" , ["down" ,"down" ,"down" ,"enter" ,"enter" ])])) 94 95class Runner : 96def __init__ (self ,s ,** kw ): 97self .s ,self .emit = s ,kw ["emit" ] 98 99def run (self ,start = True ): 100from strata_cli .launch .runner import Event ,Result 101self .emit (Event ("engine" ,"Engine 0.1.45 (cuda) is installed." ,100 )) 102self .emit (Event ("model" ,"Downloading 41.0 of 75.8 GB" ,54.0 )) 103time .sleep (1.2 ) 104self .emit (Event ("model" ,"Model is ready." ,100 )) 105self .emit (Event ("config" ,"Settings are saved." ,100 )) 106self .emit (Event ("tune" ,"Tuning" ,62.0 ,data = {"round" : (5 ,8 ),"minutes_left" :7 , 107"speeds" : [{"label" :"Default settings" ,"decode_tok_s" :83.0 }, 108 {"label" :"Keep more context on GPU" ,"decode_tok_s" :78.5 }, 109 {"label" :"Longer prompt chunks" ,"decode_tok_s" :85.1 }]})) 110time .sleep (3 ) 111return Result ("launch-x" , ["http://127.0.0.1:8080" ],None ,"faster" , [],"/x" ) 112 113async def run_screen (): 114ctx = ctx_for (HW_12 ) 115ctx .settings = S .LaunchSettings (name = "Demo" ,family = "qwen" ,model = "IQ3_XXS" ,context = 131072 ,tune = "quick" ) 116with mock .patch ("strata_cli.launch.app.Runner" ,Runner ): 117app = LaunchApp (ctx ) 118async with app .run_test (size = SIZE )as pilot : 119await pilot .pause (0.2 ) 120app .start_preset ("Demo" )if False else app .run_launch () 121await pilot .pause (2.0 ) 122write ("run-progress" ,text_of (app ),"the progress screen while it downloads and tunes" ) 123 124asyncio .run (run_screen ()) 125 126# the monitor: Overview, Connect, quit question 127from strata_cli .launch .monitor_ext import LaunchMonitor 128 129async def monitor (): 130src = ov .Source (ov .metrics ("reading" )) 131info = {"url" :"http://127.0.0.1:8080" ,"urls" : ["http://127.0.0.1:8080" ,"http://192.168.88.21:8080" ],"key" :"sk-strata-abcdefghijklmn" , 132"model" :"qwen3.8-flash-next-iq3_xxs" ,"context" :32768 ,"profile" :"launch-x" ,"name" :"Demo" } 133app = LaunchMonitor (src ,None ,info = info ,interval = 30 ) 134async with app .run_test (size = (120 ,36 ))as pilot : 135await pilot .pause (0.6 ) 136write ("monitor-overview" ,text_of (app ),"the monitor's new Overview (view 1)" ) 137await keys (pilot ,"7" ) 138write ("monitor-connect-opencode" ,text_of (app ),"the monitor's Connect view (key 7), OpenCode selected" ) 139await keys (pilot ,"down" ,"down" ,"down" ,"down" ,"down" ) 140write ("monitor-connect-hermes" ,text_of (app ),"the Connect view, Hermes selected (its limits in plain words)" ) 141await keys (pilot ,"7" ,"q" ) 142write ("monitor-quit" ,text_of (app ),"q asks: keep serving or stop" ) 143 144asyncio .run (monitor ()) 145for p in patches : 146p .stop () 147Path (OUT / "launch-overview-ascii.txt" ).write_text ( 148"# strata monitor Overview in the classic Windows console mode (--glyphs ascii, or detected): no characters Consolas lacks\n\n" 149+ ov .draw (ov .overview .build (ov .metrics ("generating" )),glyphs = "ascii" ,color = False ,connect = True ),encoding = "utf-8" ) 150 151 152if __name__ == "__main__" : 153run ()