okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221launch: text previews of every screen, advanced table widths4e6a1b46b

main
8.0 KiB153 linesraw
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
3    python 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):
34    cat = catalog(hw)
35    comp = cat.computer()
36    return 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:
40    body = 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    print("wrote", f"launch-{name}.txt")
43
44
45async def keys(pilot, *ks):
46    for k in ks:
47        await pilot.press(k)
48        await pilot.pause(0.15)
49
50
51def run() -> None:
52    OUT.mkdir(parents=True, exist_ok=True)
53    with Home():
54        store.save(S.LaunchSettings(name="IQ3_XXS 128K - Full speed", family="qwen", model="IQ3_XXS", context=131072, parallel=1,
55                                    tuned_preset="x", tuned_at="2026-10-16", last_used="2026-10-16 09:00:00"))
56        store.save(S.LaunchSettings(name="Coder 64K - agents", family="coder", model="IQ1_M", context=65536, parallel=2, last_used="2026-10-14 09:00:00"))
57        store.save(S.LaunchSettings(name="Network serving", family="qwen", model="Q2_0", context=32768, parallel=1, tuned_preset="y",
58                                    tuned_at="2026-10-15", last_used="2026-10-15 09:00:00"))
59        base = {"exe": "component:strata-engine", "args": ["--max-context", "131072", "--kv", "int8", "--prefill", "auto", "--expert-cache", "auto",
60                                                          "--spec", "4"]}
61        help_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")
64        patches = [mock.patch.object(Ctx, "base_config", lambda self: base), mock.patch.object(Ctx, "engine_exe", lambda self: "/engine/strata"),
65                   mock.patch("strata_cli.launch.params.engine_help_text", return_value=help_text),
66                   mock.patch.object(access, "lan_ips", return_value=["192.168.88.21"]),
67                   mock.patch.object(access, "find_cloudflared", return_value="/usr/bin/cloudflared"),
68                   mock.patch.object(access, "tailscale_status", return_value={"installed": False, "running": False, "ip": None, "name": None})]
69        for p in patches:
70            p.start()
71
72        async def tour(hw, prefix, steps_after_start):
73            ctx = ctx_for(hw)
74            app = LaunchApp(ctx)
75            async with app.run_test(size=SIZE) as pilot:
76                await pilot.pause(0.3)
77                write(f"{prefix}start", text_of(app), "start screen with saved presets")
78                for name, ks in steps_after_start:
79                    await keys(pilot, *ks)
80                    write(f"{prefix}{name}", text_of(app), name)
81
82        asyncio.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        ]))
93        asyncio.run(tour(HW_2X16, "twocards-", [("step2-cards", ["down", "down", "down", "enter", "enter"])]))
94
95        class Runner:
96            def __init__(self, s, **kw):
97                self.s, self.emit = s, kw["emit"]
98
99            def run(self, start=True):
100                from strata_cli.launch.runner import Event, Result
101                self.emit(Event("engine", "Engine 0.1.45 (cuda) is installed.", 100))
102                self.emit(Event("model", "Downloading 41.0 of 75.8 GB", 54.0))
103                time.sleep(1.2)
104                self.emit(Event("model", "Model is ready.", 100))
105                self.emit(Event("config", "Settings are saved.", 100))
106                self.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}]}))
110                time.sleep(3)
111                return Result("launch-x", ["http://127.0.0.1:8080"], None, "faster", [], "/x")
112
113        async def run_screen():
114            ctx = ctx_for(HW_12)
115            ctx.settings = S.LaunchSettings(name="Demo", family="qwen", model="IQ3_XXS", context=131072, tune="quick")
116            with mock.patch("strata_cli.launch.app.Runner", Runner):
117                app = LaunchApp(ctx)
118                async with app.run_test(size=SIZE) as pilot:
119                    await pilot.pause(0.2)
120                    app.start_preset("Demo") if False else app.run_launch()
121                    await pilot.pause(2.0)
122                    write("run-progress", text_of(app), "the progress screen while it downloads and tunes")
123
124        asyncio.run(run_screen())
125
126        # the monitor: Overview, Connect, quit question
127        from strata_cli.launch.monitor_ext import LaunchMonitor
128
129        async def monitor():
130            src = ov.Source(ov.metrics("reading"))
131            info = {"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"}
133            app = LaunchMonitor(src, None, info=info, interval=30)
134            async with app.run_test(size=(120, 36)) as pilot:
135                await pilot.pause(0.6)
136                write("monitor-overview", text_of(app), "the monitor's new Overview (view 1)")
137                await keys(pilot, "7")
138                write("monitor-connect-opencode", text_of(app), "the monitor's Connect view (key 7), OpenCode selected")
139                await keys(pilot, "down", "down", "down", "down", "down")
140                write("monitor-connect-hermes", text_of(app), "the Connect view, Hermes selected (its limits in plain words)")
141                await keys(pilot, "7", "q")
142                write("monitor-quit", text_of(app), "q asks: keep serving or stop")
143
144        asyncio.run(monitor())
145        for p in patches:
146            p.stop()
147    Path(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__":
153    run()