Terminal wizard: the Save choices stay on screen at 60x20 and 40x15, the Advanced command has its own scroll area, key hints wrap and say what Enter does; request filter explains itself and matches LIVE/DONE; plain-word setting descriptions; tuning default explained; monitor bundle carries nav.py (T09, T11)

This commit is contained in:
Niko1221 committed 2026-10-18 23:23:09 +02:00
1 parent adc4a6822b
commit bccb0f4280
13 files changed
+418 -57

No files matched your search

+8 -6
View File
@@ -30,13 +30,15 @@ SOURCES_V2 = (
"strata_cli/logs.py",
)
SOURCES_V3 = (*SOURCES_V2, "strata_cli/dashboard.py")
SOURCES = (*SOURCES_V3, "strata_cli/detail_dashboard.py")
SOURCES_V4 = (*SOURCES_V3, "strata_cli/detail_dashboard.py")
SOURCES = (*SOURCES_V4, "strata_cli/nav.py") # schema 5: the view tabs every screen shares (strata_cli/nav.py)
BOOTSTRAP = b"from strata_cli.monitor_commands import main\nraise SystemExit(main())\n"
MEMBERS_V1 = ("__main__.py", *SOURCES_V2)
LICENSE_NOTICE = "LICENSE"
MEMBERS_V2 = (*MEMBERS_V1, LICENSE_NOTICE)
MEMBERS_V3 = (*MEMBERS_V2, "strata_cli/dashboard.py")
MEMBERS = (*MEMBERS_V3, "strata_cli/detail_dashboard.py")
MEMBERS_V4 = (*MEMBERS_V3, "strata_cli/detail_dashboard.py")
MEMBERS = (*MEMBERS_V4, "strata_cli/nav.py")
COMPATIBILITY = {"python_min": "3.10", "telemetry_schema": [1]}
MAX_BUNDLE_BYTES = 1024 * 1024
MAX_MANIFEST_BYTES = 64 * 1024
@@ -72,7 +74,7 @@ def build(bundle: Path) -> dict:
if set(names) != set((*MEMBERS, "strata_cli/")) or len(names) != len(MEMBERS) + 1:
raise ValueError("bundle member list changed during build")
files = {name: digest(archive.read(name)) for name in MEMBERS}
report = {"schema_version": 4, "kind": "strata-monitor-bundle",
report = {"schema_version": 5, "kind": "strata-monitor-bundle",
"bundle": bundle.name, "sha256": digest(temp_bundle.read_bytes()),
"files": files, "interactive_dependency": "textual==8.2.8",
"compatibility": COMPATIBILITY, "license": "MIT", "license_file": LICENSE_NOTICE,
@@ -94,13 +96,13 @@ def verify(bundle: Path) -> dict:
raise ValueError("bundle and manifest must be bounded regular files")
report = json.loads(manifest_path(bundle).read_text())
if (not isinstance(report, dict) or type(report.get("schema_version")) is not int or
report["schema_version"] not in (1, 2, 3, 4) or
report["schema_version"] not in (1, 2, 3, 4, 5) or
report.get("kind") != "strata-monitor-bundle" or
report.get("publisher_signature") is not None or
report.get("bundle") != bundle.name or report.get("sha256") != digest(bundle.read_bytes())):
raise ValueError("bundle manifest or SHA-256 mismatch")
members = {1: MEMBERS_V1, 2: MEMBERS_V2, 3: MEMBERS_V3,
4: MEMBERS}[report["schema_version"]]
members = {1: MEMBERS_V1, 2: MEMBERS_V2, 3: MEMBERS_V3, 4: MEMBERS_V4,
5: MEMBERS}[report["schema_version"]]
if report["schema_version"] >= 2:
if (report.get("compatibility") != COMPATIBILITY or report.get("license") != "MIT" or
report.get("license_file") != LICENSE_NOTICE):
+1 -1
View File
@@ -89,7 +89,7 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser]
"(on the graphics card for NVIDIA and AMD, on the CPU otherwise); off turns it off")
g.add_argument("--parallel", type=_parallel, metavar="N", help="requests answered at the same time, 1 to 8 (default: fit to your graphics card)")
g.add_argument("--gpu", metavar="LIST", help="graphics card numbers to use, e.g. 0 or 0,1 (default: the engine's choice)")
g.add_argument("--tune", type=_choice("a tuning mode", S.TUNE_MODES), metavar="quick|thorough|skip", help="find the fastest settings first (default: skip)")
g.add_argument("--tune", type=_choice("a tuning mode", S.TUNE_MODES), metavar="quick|thorough|skip", help="find the fastest settings first (default: skip here; the guided screens suggest quick the first time)")
g.add_argument("--tune-allow-small", action="store_true", help="let the tuner also try settings that can change answers very slightly")
g.add_argument("--set", action="append", default=[], metavar="KEY=VALUE",
help="an advanced engine setting or STRATA_* variable, e.g. prefill=65536 (repeat); unknown names get a warning, not a refusal")
+38 -1
View File
@@ -18,6 +18,43 @@ _DEFAULT = re.compile(r"\(\s*default[: ]\s*([^)]*)\)", re.I)
_PARENS = re.compile(r"\([^)]*\)")
# Plain words for the settings people meet most. The engine's own help text is written for its developers (round codes like "R4", internal
# names); these lines say what the setting does for a person. A setting not listed here keeps the engine's sentence with the codes removed.
PLAIN = {
"--expert-cache": "How many of the model's experts stay in graphics memory (auto picks the most that fit your card).",
"--prefill": "How many prompt tokens are read in one go (auto picks for your card).",
"--spec": "How many words the draft layer guesses ahead to speed up answers.",
"--spec-min-p": "How sure the draft layer must be before a guess is used.",
"--mtp": "The draft layer that makes answers faster.",
"--pack": "The folder with the model's prepared data.",
"--native": "The model file.",
"--ple-gguf": "The model file that holds the word-embedding table.",
"--expert-profile": "A table of which experts are used most, to decide what stays in graphics memory.",
"--max-context": "How much text the model remembers at once.",
"--kv": "The format of the conversation memory (int8 uses half of fp16; q4_0 uses less still).",
"--kv-resident": "How much of the conversation memory stays in graphics memory.",
"--vision": "Let the model read pictures.",
"--vram-reserve-mib": "Graphics memory (in MiB) kept free for other programs.",
"--adapt-every": "How often the engine re-chooses which experts stay in graphics memory.",
"--pcie-frac": "How much of the link to the graphics card is used for moving experts.",
"--suffix-draft": "Guess the next words from text already in the conversation.",
"--port": "The network port the server listens on.",
"--gpu": "Which graphics card to use.",
"--gpus": "Which graphics cards to use together.",
}
_CODE = re.compile(r"\b[RTS]\d{1,2}\b[:,)]?\s*")
def plain_description(name: str, text: str) -> str:
"""A person's sentence for a setting: ours when we have one, else the engine's with its internal round codes ("R4", "T2") taken out."""
if name in PLAIN:
return PLAIN[name]
cleaned = _CODE.sub("", text or "").strip(" :;,-")
cleaned = re.sub(r"\(\s*\)", "", cleaned).strip()
cleaned = re.sub(r"\s{2,}", " ", cleaned)
return cleaned[:1].upper() + cleaned[1:] if cleaned else "An engine setting (the engine's help has no sentence for it)."
@dataclass
class Param:
name: str # --flag or ENV_NAME
@@ -33,7 +70,7 @@ class Param:
"""One line: the first sentence, cut at 70 characters."""
text = re.sub(r"\s+", " ", re.sub(r"\([^)]*\)", "", self.description)).strip()
cut = re.split(r"(?<=[.;:])\s", text, maxsplit=1)[0] if text else ""
cut = cut.rstrip(".;:")
cut = plain_description(self.name, cut.rstrip(".;:")).rstrip(".;:")
return cut if len(cut) <= 70 else cut[:67].rstrip() + "..."
+96 -23
View File
@@ -16,7 +16,7 @@ from typing import Any
from rich.text import Text
from textual.app import ComposeResult
from textual.binding import Binding
from textual.containers import Vertical
from textual.containers import Vertical, VerticalScroll
from textual.screen import ModalScreen, Screen
from textual.widgets import Input, Static
@@ -127,7 +127,9 @@ class Base(Screen):
self.query_one("#head", Static).update(self.head_text())
self.query_one("#rule1", Static).update(Text(self.rule(), style=MUTE))
self.query_one("#rule2", Static).update(Text(self.rule(), style=MUTE))
self.query_one("#explain", Static).update(self.explain())
explanation = self.explain()
self.query_one("#explain", Static).update(explanation)
self.query_one("#explain", Static).display = bool(explanation.plain.strip()) # no empty row where there is nothing to say
self.query_one("#hints", Static).update(Text(self.hints_text(), style=MUTE))
self.query_one("#message", Static).update(Text(self.message, style=WARN if self.message.startswith("!") else MUTE))
except Exception: # noqa: BLE001 - a screen that is closing
@@ -912,7 +914,8 @@ class TuningScreen(Base):
def on_mount(self) -> None:
s = self.ctx.settings
items = [Item(["Quick", "about 20 minutes", "checks the most likely gains"], key="quick"),
first = self.ctx.fresh_setup and not s.tuned_preset
items = [Item(["Quick", "about 20 minutes", "checks the most likely gains" + ("; suggested the first time" if first else "")], key="quick"),
Item(["Thorough", "up to 2 hours", "tries more settings, measures each one several times"], key="thorough"),
Item(["Skip", "", "use the default settings (already good on most computers)"], key="skip")]
if not self.ctx.tune_chosen and s.tune == "skip" and not s.tuned_preset and self.ctx.fresh_setup:
@@ -926,9 +929,8 @@ class TuningScreen(Base):
f"\n [{'x' if on else ' '}] Allow settings that change answers very slightly (same quality) press a to change", style=MUTE))
def explain(self) -> Text:
return Text("Tuning is optional. It tries single changes against your settings, keeps only gains above the noise, and saves the "
"result as a preset the Strata app can use too. Close other heavy programs while it measures. If your computer is "
"already at its best it says so and changes nothing.", style=MUTE)
return Text("Tuning is optional: it keeps only real gains, and the result is a preset the Strata app can use too. Close other heavy "
"programs while it measures. The command line skips tuning unless you add --tune.", style=MUTE)
def action_allow(self) -> None:
self.ctx.settings.tune_allow_small = not self.ctx.settings.tune_allow_small
@@ -943,19 +945,21 @@ class TuningScreen(Base):
class AdvancedScreen(Base):
step_id = "advanced"
hints = "↑↓ choose Enter edit Del reset x experimental / filter a add by name c copy command n next Esc back"
hints = "n next ↑↓ choose Enter edit Esc back Del reset x experimental / filter a add by name c copy command Tab scroll command"
help_text = ("Every engine setting with its default, the value the tuner chose and your own value. You never have to touch this. "
"A name the engine does not list gets a warning, not a refusal.")
BINDINGS = [b for b in Base.BINDINGS if b.key != "enter"] + [
Binding("enter", "edit", show=False), Binding("delete", "reset", show=False), Binding("backspace", "reset", show=False),
Binding("x", "experimental", show=False), Binding("slash", "filter", show=False), Binding("a", "add", show=False),
Binding("c", "copy", show=False), Binding("n", "go_next", show=False), Binding("right", "go_next", show=False)]
Binding("c", "copy", show=False), Binding("n", "go_next", show=False), Binding("right", "go_next", show=False),
Binding("tab", "scroll_command", show=False)]
def body(self) -> ComposeResult:
yield Static("", id="advhead", markup=False)
yield Menu([("Setting", 24), ("Default", 11), ("Tuned", 13), ("Yours", 10), ("What it does", 0)], id="menu", window=8)
yield Static("", id="cmdline", markup=False)
with VerticalScroll(id="cmdbox"): # the long command has its own scroll area (Tab, then the arrows) instead of running off the screen
yield Static("", id="cmdline", markup=False)
yield Input(id="edit", classes="field", disabled=True)
def on_mount(self) -> None:
@@ -983,7 +987,10 @@ class AdvancedScreen(Base):
key=r.name))
items.append(Item([Cell("+ Add a setting by name…", ""), "", "", "", Cell("for flags of newer engine versions", MUTE)], key="__add__"))
m = self.query_one(Menu)
m.window = max(4, (self.size.height or 30) - 15)
body_h = self.query_one("#body").size.height or max(6, (self.size.height or 30) - 8)
box_h = max(3, min(8, body_h // 3))
self.query_one("#cmdbox").styles.height = box_h
m.window = max(3, body_h - box_h - 4) # the heading, the column titles, the "n of m" line and the box's rule
m.set_items(items, min(m.index, len(items) - 1))
def on_resize(self, _e) -> None:
@@ -993,23 +1000,33 @@ class AdvancedScreen(Base):
def refresh_body(self) -> None:
eng = self.ctx.engine_note
t = Text()
t = Text(no_wrap=True, overflow="ellipsis")
t.append("All settings", style=f"bold {ACCENT}")
t.append(" (optional · for tinkerers)", style=MUTE)
extra = " / filter" + (f": {self.filter}" if self.filter else "") + " x show experimental only" + (" (on)" if self.only_experimental else "")
if self.width() >= 70:
t.append(" (optional · for tinkerers)", style=MUTE)
extra = " / filter" + (f": {self.filter}" if self.filter else "") + " x show experimental only" + (" (on)" if self.only_experimental else "")
else:
extra = " (optional)" + (f" filter: {self.filter}" if self.filter else "") + (" experimental only" if self.only_experimental else "")
t.append(extra, style=MUTE)
self.query_one("#advhead", Static).update(t)
s = self.ctx.settings
cmd = self.ctx.command_text()
out = Text()
out.append("Command that will run\n", style=f"bold {ACCENT}")
out.append("Command that will run (your choices above are in it)\n", style=f"bold {ACCENT}")
out.append(" " + cmd + "\n")
out.append(" Same as: " + S.flags_text(s) + "\n", style=MUTE)
if eng:
out.append(" " + eng, style=WARN)
self.query_one("#cmdline", Static).update(out)
def hints_text(self) -> str:
if (self.size.width or 80) < 60:
return "n next Enter edit Esc back Tab command"
return super().hints_text()
def explain(self) -> Text:
if (self.size.height or 30) < 20:
return Text("") # a small window: the list and the command matter more than the sentence under them
m = self.menu()
cur = m.current if m else None
if cur is not None and cur.key not in (None, "__add__"):
@@ -1105,6 +1122,15 @@ class AdvancedScreen(Base):
except Exception: # noqa: BLE001
self.say("Your terminal does not allow copying; select the lines above with the mouse.", True)
def action_scroll_command(self) -> None:
box = self.query_one("#cmdbox")
if box.has_focus:
self.set_focus(None)
self.say("")
else:
box.focus()
self.say("Up/Down/PageUp/PageDown scroll the command; Tab or Esc goes back to the list.")
def action_go_next(self) -> None:
if self.mode:
return
@@ -1119,6 +1145,10 @@ class AdvancedScreen(Base):
self.close_field("edit")
self.say("")
return
if self.query_one("#cmdbox").has_focus:
self.set_focus(None)
self.say("")
return
super().action_back()
def action_move(self, step: int) -> None:
@@ -1272,13 +1302,19 @@ class SaveScreen(Base):
self.query_one(Menu).set_items(items, 0)
self.paint()
def refresh_body(self) -> None:
def hints_text(self) -> str:
cur = self.menu().current if self.menu() else None
label = (cur.cells[0] if isinstance(cur.cells[0], str) else cur.cells[0].text) if cur is not None else "do it"
if (self.size.width or 80) < 60:
return f"Enter: {label} Esc back"
return f"{self.g.updown} choose Enter: {label} Tab rename Esc back ? help"
def on_cursor(self) -> None:
self.paint()
def summary_lines(self) -> list[tuple[str, str]]:
s = self.ctx.settings
r = next((x for x in self.ctx.rows if (x.family, x.model) == (s.family, s.model)), None)
t = Text()
t.append("Save as preset, then launch\n", style=f"bold {ACCENT}")
t.append(" Name ")
t.append("(type below)\n", style=MUTE)
lines = [("Model", (r.title if r else (s.model or "?")) + (" (your files)" if s.model_path else "")),
("Context", S.context_label(s.context) + f", memory {s.kv or 'int8'}"),
("Pictures", "on" if s.vision != "off" else "off"),
@@ -1288,13 +1324,50 @@ class SaveScreen(Base):
("Storage", s.data_dir or "Strata's data folder")]
if s.extra:
lines.append(("Advanced", ", ".join(f"{k}={v}" for k, v in s.extra.items())))
for k, v in lines:
t.append(f" {k:<10}{v}\n")
for n in self.ctx.warnings():
t.append(f" ! {n}\n", style=WARN)
return lines
def refresh_body(self) -> None:
"""The summary, the name and the three choices. When the body is too short for all of it (a small window), the summary shrinks to a
few short lines and the name field to one row, so the three choices stay on screen and Enter never acts on something you cannot see."""
s = self.ctx.settings
lines = self.summary_lines()
warnings = self.ctx.warnings()
body_h = self.query_one("#body").size.height
full_need = 2 + len(lines) + len(warnings) + 3 + 3
compact = bool(body_h) and full_need > body_h
name = self.query_one("#name", Input)
name.set_class(compact, "slim")
if compact:
t = Text(no_wrap=True, overflow="ellipsis")
tiny = body_h < 9
model = dict(lines)["Model"].replace("Qwen3.8-Flash-Next ", "")
rows = [f"{model} \u00b7 {S.context_label(s.context)} \u00b7 memory {s.kv or 'int8'}",
f"Pictures {'on' if s.vision != 'off' else 'off'} \u00b7 Parallel {s.parallel or 'auto'} \u00b7 Tuning {s.tune}",
f"Access {s.access}, port {s.port}" + (f" \u00b7 Storage {s.data_dir}" if s.data_dir else "")]
t.append("Save, then launch name:\n" if tiny else "Save as preset, then launch name:\n", style=f"bold {ACCENT}")
for ln in rows[:2 if tiny else 3]:
t.append(" " + ln + "\n")
if warnings and not tiny:
t.append(f" ! {warnings[0]}" + (f" (+{len(warnings) - 1} more)" if len(warnings) > 1 else "") + "\n", style=WARN)
t.rstrip()
else:
t = Text()
t.append("Save as preset, then launch\n", style=f"bold {ACCENT}")
t.append(" Name ")
t.append("(type below)\n", style=MUTE)
for k, v in lines:
t.append(f" {k:<10}{v}\n")
for n in warnings:
t.append(f" ! {n}\n", style=WARN)
t.rstrip()
self.query_one("#summary", Static).update(t)
if getattr(self, "_compact", None) != compact: # the body's height changes with it: look again once the layout has settled
self._compact = compact
self.call_after_refresh(self.paint)
def explain(self) -> Text:
if (self.size.height or 30) < 20:
return Text("") # a small window: the choices matter more than the sentence
st = self.ctx.model_state()
if st.remaining_gb < 0.05:
fetch = "Nothing needs to be downloaded."
+4 -2
View File
@@ -77,12 +77,14 @@ Screen {{ background: {BG}; color: {FG}; }}
#shell {{ width: 100%; height: 100%; background: {PANEL}; padding: 0 1; }}
#head {{ height: 1; }}
#rule1, #rule2 {{ height: 1; color: {RULE}; }}
#body {{ height: 1fr; }}
#body {{ height: 1fr; overflow-y: auto; }}
#explain {{ height: auto; max-height: 4; color: {MUTE}; }}
#hints {{ height: 1; color: {MUTE}; }}
#hints {{ height: auto; max-height: 3; color: {MUTE}; }}
#message {{ height: auto; max-height: 3; color: {MUTE}; }}
Menu {{ height: auto; max-height: 100%; }}
.field {{ height: 3; border: solid {ACCENT}; display: none; }}
.field.slim {{ height: 1; border: none; padding: 0 1; background: {SEL}; }}
#cmdbox {{ height: 6; border-top: solid {RULE}; scrollbar-size-vertical: 1; }}
.field.open {{ display: block; }}
Input {{ background: {PANEL}; color: {FG}; }}
"""
+1 -1
View File
@@ -152,7 +152,7 @@ class MonitorApp(App):
def compose(self) -> ComposeResult:
with Vertical(id="shell"):
yield Static("", id="content", markup=False)
yield Input(placeholder="Filter request state, then Enter", max_length=80, id="filter")
yield Input(placeholder="Filter by request id, state, live or done, then Enter", max_length=80, id="filter")
yield Static("Read only | q detaches without stopping Strata", id="message", markup=False)
def on_mount(self) -> None:
+4 -4
View File
@@ -10,8 +10,6 @@ from __future__ import annotations
from dataclasses import dataclass
from rich.text import Text
NAMES = ("Overview", "Serving", "Requests", "Engine", "Hardware", "Logs", "Connect")
SHORT = ("Over", "Serve", "Reqs", "Engine", "GPU", "Logs", "Conn")
@@ -75,8 +73,10 @@ def plain(current: int, width: int, connect: bool = False) -> str:
return line[:max(1, width)]
def styled(current: int, width: int, connect: bool = False, *, accent: str = "", color: bool = True) -> Text:
"""The same line as rich Text: the selected tab in bold and the accent colour (just bold, in brackets, without colour)."""
def styled(current: int, width: int, connect: bool = False, *, accent: str = "", color: bool = True):
"""The same line as rich Text: the selected tab in bold and the accent colour (just bold, in brackets, without colour).
(rich is imported here: the plain-text parts of this module also run in the thin stdlib-only monitor bundle.)"""
from rich.text import Text
tabs = layout(current, width, connect)
out = Text(no_wrap=True, overflow="crop")
if tabs.left:
+16 -8
View File
@@ -193,11 +193,19 @@ def request_rows(snapshot: dict, filter_text: str = "", *, limit: int | None = N
recent = (snapshot.get("recent") or [])[:limit]
needle = filter_text.lower()
if needle:
live = [row for row in live if needle in (safe(row.get("id")) + safe(row.get("state"))).lower()]
recent = [row for row in recent if needle in (safe(row.get("id")) + safe(row.get("finish"))).lower()]
# what the screen calls the row counts too: LIVE for a request in flight, DONE for a finished one
live = [row for row in live if needle in (safe(row.get("id")) + " " + safe(row.get("state")) + " live").lower()]
recent = [row for row in recent if needle in (safe(row.get("id")) + " " + safe(row.get("finish")) + " done").lower()]
return live, recent
def no_requests_text(filter_text: str = "") -> str:
"""The empty-list sentence: with a filter on it says so and names the filter, so an empty page is never a mystery."""
if not filter_text:
return "No request summaries"
return f"No requests match this filter ({safe(filter_text, 30)}). It looks at the id, the state, and live or done. Esc clears it."
def activity_rows(snapshot: dict, filter_text: str = "") -> list[dict]:
rows = (snapshot.get("activity") or {}).get("events") or []
needle = filter_text.lower()
@@ -350,14 +358,14 @@ def _wide_serving(lines: list[str], snapshot: dict, width: int, height: int,
# When height is scarce, preserve pressure outside the batch window; slot rows remain in the Groups pane.
all_requests = work.get("requests") or []
requests = sorted((row for row in all_requests if not filter_text or
filter_text.lower() in (safe(row.get("id")) + safe(row.get("state"))).lower()),
filter_text.lower() in (safe(row.get("id")) + " " + safe(row.get("state")) + " live").lower()),
key=lambda row: row.get("slot") is not None)
if requests:
for row in requests:
wait = _queue_wait(row, snapshot.get("sampled_at"))
left.append(_line(f"{field(row.get('id'), 12)} {_replica_short(row)}s{number(row.get('slot')):<2} g{number(row.get('group')):<2} {field(row.get('state'), 9)} wait {number(wait, 's', 1):<6} {_request_work(row)}", left_width))
elif all_requests:
left.append("No matching request summaries")
left.append(no_requests_text(filter_text) if filter_text else "No matching request summaries")
else:
left.append("Request identity unavailable; showing engine slots")
for row in work.get("slots") or []:
@@ -502,7 +510,7 @@ def render_view(snapshot: dict, view: str, width: int = 80, height: int = 24,
lines += [f"Prompt {number(row.get('prompt_tokens'))} tokens",
f"Wait {number(_queue_wait(row, sampled), ' s', 1)} Engine first {number(row.get('first_engine_token_s'), ' s', 2)}"]
else:
lines += ["No request summaries"]
lines += [no_requests_text(filter_text)]
elif view == "serving":
optional = [_batch_window(work, width), _stage_in_flight(work, width)]
if not tiny:
@@ -593,7 +601,7 @@ def render_view(snapshot: dict, view: str, width: int = 80, height: int = 24,
lines.append("")
if serving_pane == "requests":
rows = [r for r in (work.get("requests") or []) if not filter_text or
filter_text.lower() in (safe(r.get("id")) + safe(r.get("state"))).lower()]
filter_text.lower() in (safe(r.get("id")) + " " + safe(r.get("state")) + " live").lower()]
capacity = max(1, height - len(lines) - (10 if detail and rows else 4))
start = min(max(0, selected - capacity // 2), max(0, len(rows) - capacity))
lines += [f"Requests {start + 1 if rows else 0}-{min(start + capacity, len(rows))} of {len(rows)} (Up/Down scroll; wait is queue time)"]
@@ -636,7 +644,7 @@ def render_view(snapshot: dict, view: str, width: int = 80, height: int = 24,
elif view == "requests":
active, shown = request_rows(snapshot, filter_text)
rows = [("LIVE", row) for row in active] + [("DONE", row) for row in shown]
lines += [f"Live {len(active)} / recent {len(shown)} No prompt bodies", ""]
lines += [f"Live {len(active)} / recent {len(shown)} No prompt bodies" + (f" Filter: {safe(filter_text, 20)} (Esc clears)" if filter_text else ""), ""]
if rows:
index = min(max(0, selected), len(rows) - 1)
capacity = max(1, height - len(lines) - (10 if detail else 4))
@@ -654,7 +662,7 @@ def render_view(snapshot: dict, view: str, width: int = 80, height: int = 24,
kind, row = rows[index]
lines += (_request_detail(row, sampled, width) if kind == "LIVE" else _recent_detail(row, width))
else:
lines.append("No request summaries")
lines.append(no_requests_text(filter_text))
elif view == "engine":
lines += [f"Context capacity {number(model.get('context'), ' tokens')}",
f"Batch groups {number(work.get('groups'))}",
+1 -1
View File
@@ -172,7 +172,7 @@ def places(*, here: Path | None = None, explicit: str | os.PathLike | None = Non
seen.add(key)
n = len(config_files(path))
if n:
out.append(Place(path.resolve() if path.exists() else path, source, n))
out.append(Place(path if source == "here" else (path.resolve() if path.exists() else path), source, n))
return out
+11 -4
View File
@@ -52,7 +52,10 @@ class ExistingInstallIsFoundInPlace(unittest.TestCase):
d.mkdir()
env = mock.patch.dict(os.environ, {"APPDATA": str(self.appdata), "XDG_CONFIG_HOME": str(self.appdata),
"STRATA_PROFILE_DIR": str(self.profiles),
"STRATA_RUNTIME_DIR": str(base / "runtime")})
"STRATA_RUNTIME_DIR": str(base / "runtime"),
# the desktop app's folders of whoever runs the tests are not part of this fixture
"LOCALAPPDATA": str(base / "local"), "XDG_DATA_HOME": str(base / "localshare"),
"STRATA_COMPONENTS_DIR": ""})
env.start()
self.addCleanup(env.stop)
os.environ.pop("STRATA_INSTALL_DIR", None)
@@ -150,12 +153,16 @@ class ExistingInstallIsFoundInPlace(unittest.TestCase):
self.assertEqual(models.resolve_install()[1], "explicit")
def test_nothing_remembered_means_this_folder_and_no_error(self):
# nothing found anywhere: the folder a new model would be installed into (the desktop app's, which the Terminal shares), no error
from strata_control import discovery
default = (discovery.app_install_dir(), "default")
setup.settings_path().unlink()
self.assertEqual(models.resolve_install(), (self.terminal, "default"))
self.assertEqual(models.resolve_install(), default)
setup.settings_path().write_text("not json")
self.assertEqual(models.resolve_install(), (self.terminal, "default"))
self.assertEqual(models.resolve_install(), default)
setup.settings_path().write_text(json.dumps({"installs": ["relative/path", 7, str(self.base / "gone")]}))
self.assertEqual(models.resolve_install(), (self.terminal, "default"))
self.assertEqual(models.resolve_install(), default)
self.assertEqual(models.list_installed()["models"], [])
def test_the_settings_path_is_the_one_setup_writes(self):
self.assertEqual(models.settings_path(), setup.settings_path())
+6 -5
View File
@@ -65,7 +65,7 @@ class MonitorBundleTests(unittest.TestCase):
build(bundle)
with zipfile.ZipFile(bundle) as archive:
self.assertIn(b"MIT License\r\n", archive.read("LICENSE"))
self.assertEqual(verify(bundle)["schema_version"], 4)
self.assertEqual(verify(bundle)["schema_version"], 5)
def test_update_rollback_and_commit_keep_one_verified_previous_copy(self):
with tempfile.TemporaryDirectory() as directory:
@@ -293,7 +293,7 @@ class MonitorBundleTests(unittest.TestCase):
for old_bundle, version in ((current, 1), (previous, 2), (old_visual, 3)):
with zipfile.ZipFile(modern) as source, zipfile.ZipFile(old_bundle, "w", zipfile.ZIP_DEFLATED) as legacy:
for item in source.infolist():
if item.filename != "strata_cli/detail_dashboard.py" and \
if item.filename not in ("strata_cli/detail_dashboard.py", "strata_cli/nav.py") and \
(version >= 3 or item.filename != "strata_cli/dashboard.py") and \
(version != 1 or item.filename != "LICENSE"):
legacy.writestr(item, source.read(item.filename))
@@ -302,6 +302,7 @@ class MonitorBundleTests(unittest.TestCase):
report["bundle"] = old_bundle.name
report["sha256"] = hashlib.sha256(old_bundle.read_bytes()).hexdigest()
del report["files"]["strata_cli/detail_dashboard.py"]
del report["files"]["strata_cli/nav.py"]
if version < 3:
del report["files"]["strata_cli/dashboard.py"]
if version == 1:
@@ -312,7 +313,7 @@ class MonitorBundleTests(unittest.TestCase):
self.assertEqual(verify(current)["schema_version"], 1)
self.assertEqual(verify(previous)["schema_version"], 2)
self.assertEqual(verify(old_visual)["schema_version"], 3)
self.assertEqual(verify(modern)["schema_version"], 4)
self.assertEqual(verify(modern)["schema_version"], 5)
with zipfile.ZipFile(modern) as archive:
self.assertIn(b"MIT License", archive.read("LICENSE"))
self.assertIn(b"render_dashboard", archive.read("strata_cli/dashboard.py"))
@@ -323,7 +324,7 @@ class MonitorBundleTests(unittest.TestCase):
self.assertTrue(preview["would_update"])
self.assertTrue(update(modern, target, if_current_sha256=preview["current_sha256"],
if_candidate_sha256=preview["candidate_sha256"])["updated"])
self.assertEqual(verify(target / modern.name)["schema_version"], 4)
self.assertEqual(verify(target / modern.name)["schema_version"], 5)
self.assertEqual(verify(root / "optional-monitor.previous" / current.name)["schema_version"], 1)
planned = rollback(target, plan=True)
self.assertTrue(rollback(target, if_active_sha256=planned["active_sha256"],
@@ -335,7 +336,7 @@ class MonitorBundleTests(unittest.TestCase):
self.assertTrue(update(modern, second_target,
if_current_sha256=preview["current_sha256"],
if_candidate_sha256=preview["candidate_sha256"])["updated"])
self.assertEqual(verify(second_target / modern.name)["schema_version"], 4)
self.assertEqual(verify(second_target / modern.name)["schema_version"], 5)
planned = rollback(second_target, plan=True)
self.assertTrue(rollback(second_target, if_active_sha256=planned["active_sha256"],
if_rollback_sha256=planned["rollback_sha256"])["rolled_back"])
+1 -1
View File
@@ -221,7 +221,7 @@ class LightTheme(unittest.TestCase):
def run_app(self, coro, size=(120, 40)):
async def go():
app = LaunchMonitor(Source(metrics("idle")), None, info=dict(INFO), interval=30, theme="light")
app = LaunchMonitor(Source(metrics("idle")), None, info=dict(INFO), interval=30, theme="light", color="always")
async with app.run_test(size=size) as pilot:
await pilot.pause(0.4)
return await coro(app, pilot)
+231
View File
@@ -0,0 +1,231 @@
"""Tester report T05, T09, T11 and the smaller wizard items, with Textual's pilot at 120x40, 80x24, 60x20 and 40x15: the Folder step knows an installed
model, the Advanced command follows the choices, the final choices stay on screen, the key hints wrap instead of being cut off."""
from __future__ import annotations
import asyncio
import json
import os
import unittest
from pathlib import Path
from unittest import mock
from strata_cli.launch import settings as S
from strata_cli.launch.app import Ctx, LaunchApp
from strata_cli.launch import params as P
from tests.terminal.launch_support import HW_12, Home, text_of
from tests.terminal.test_launch_tui import FakeRunner, make_ctx, press, flat, typed
SIZES = ((120, 40), (80, 24), (60, 20), (40, 15))
class Base(unittest.TestCase):
def setUp(self):
self.home = Home().__enter__()
self.addCleanup(self.home.__exit__, None, None, None)
FakeRunner.instances.clear()
FakeRunner.behaviour = "ok"
FakeRunner.download = 0.0
p = mock.patch("strata_cli.launch.app.Runner", FakeRunner)
p.start()
self.addCleanup(p.stop)
def run_app(self, coro, ctx=None, size=(120, 40)):
ctx = ctx or make_ctx()
app = LaunchApp(ctx)
async def go():
async with app.run_test(size=size) as pilot:
await pilot.pause(0.2)
return await coro(app, pilot, ctx)
return asyncio.run(go())
class SaveChoices(Base):
def test_the_three_choices_and_the_name_are_on_screen_at_every_size(self):
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7, "n", "enter")
for size in SIZES:
await pilot.resize_terminal(*size)
await pilot.pause(0.3)
shown = text_of(app)
for choice in ("Save as a preset and launch", "Launch without saving", "Save the preset and stop here"):
self.assertIn(choice, shown, (size, shown))
body = app.screen.query_one("#body")
menu = app.screen.menu()
self.assertLessEqual(menu.region.bottom, body.region.bottom, size) # the choices are inside the body, not below it
self.assertGreaterEqual(menu.region.y, body.region.y, size)
name = app.screen.query_one("#name")
self.assertLessEqual(name.region.bottom, body.region.bottom, size)
self.assertIn("Enter:", flat(app), size) # the footer says which action Enter does
self.run_app(case)
def test_the_footer_names_the_action_enter_will_do(self):
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7, "n", "enter")
self.assertIn("Enter: Save as a preset and launch", flat(app))
await press(pilot, "down")
self.assertIn("Enter: Launch without saving", flat(app))
await press(pilot, "down")
self.assertIn("Enter: Save the preset and stop here", flat(app))
self.run_app(case)
def test_the_full_layout_is_kept_when_it_fits(self):
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7, "n", "enter")
shown = text_of(app)
for part in ("Save as preset, then launch", "Context", "Pictures", "Parallel", "Tuning", "Access", "Storage"):
self.assertIn(part, shown)
self.run_app(case)
class AdvancedLayout(Base):
HELP = " --prefill N prompt chunk size (default 2048)\n --kv fp16|int8 KV storage\n"
def ctx_with_engine(self, **choices):
ctx = make_ctx()
ctx.settings.family, ctx.settings.model = "qwen", "IQ3_XXS"
for k, v in choices.items():
setattr(ctx.settings, k, v)
base = {"exe": "component:strata-engine", "vision": {"mmproj": "/x/mmproj.gguf", "gpu": False},
"args": ["--native", "/very/long/path/to/the/models/folder/Qwen3.8-Flash-Next-Something-IQ3_XXS-00001-of-00002.gguf",
"--pack", "/very/long/path/to/the/data/packs/iq3_xxs", "--max-context", "131072", "--kv", "int8", "--prefill", "auto",
"--vision"]}
for p in (mock.patch.object(Ctx, "base_config", lambda self: base), mock.patch.object(Ctx, "engine_exe", lambda self: "/engine/strata"),
mock.patch("strata_cli.launch.params.engine_help_text", return_value=self.HELP)):
p.start()
self.addCleanup(p.stop)
return ctx
def test_the_command_follows_the_wizard_choices(self):
ctx = self.ctx_with_engine(context=102400, kv="q4_0", vision="off")
cmd = ctx.command_text()
self.assertIn("--max-context 102400", cmd)
self.assertIn("--kv q4_0", cmd)
self.assertNotIn("--vision", cmd)
self.assertNotIn("131072", cmd)
ctx2 = self.ctx_with_engine(context=65536, kv="int8", vision="cpu")
cmd2 = ctx2.command_text()
self.assertIn("--max-context 65536", cmd2)
self.assertIn("--vision", cmd2)
# and the "Same as" line agrees with it
self.assertIn("--context 100k", S.flags_text(ctx.settings))
self.assertIn("--kv q4_0", S.flags_text(ctx.settings))
self.assertIn("--vision off", S.flags_text(ctx.settings))
def test_the_preview_is_inside_its_own_scroll_area_at_every_size_and_the_next_key_is_visible(self):
ctx = self.ctx_with_engine(context=102400, kv="q4_0", vision="off")
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7)
self.assertEqual(app.current, "advanced")
for size in SIZES:
await pilot.resize_terminal(*size)
await pilot.pause(0.3)
body = app.screen.query_one("#body")
box = app.screen.query_one("#cmdbox")
self.assertGreaterEqual(box.region.y, body.region.y, size)
self.assertLessEqual(box.region.bottom, body.region.bottom, size) # the preview never leaves the body
self.assertGreaterEqual(box.region.height, 3, size)
self.assertIn("n next", flat(app), size) # the key hints wrap instead of being cut off
self.assertIn("Command that will run", text_of(app), size)
self.run_app(case, ctx)
def test_tab_scrolls_the_preview_and_esc_comes_back(self):
ctx = self.ctx_with_engine(context=102400, kv="q4_0", vision="off")
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7)
await pilot.resize_terminal(60, 20)
await pilot.pause(0.3)
await press(pilot, "tab")
self.assertTrue(app.screen.query_one("#cmdbox").has_focus)
await press(pilot, "down", "down")
await press(pilot, "escape")
self.assertFalse(app.screen.query_one("#cmdbox").has_focus)
self.assertEqual(app.current, "advanced") # Esc only gave the focus back; it did not leave the step
await press(pilot, "n")
self.assertEqual(app.current, "access")
self.run_app(case, ctx)
def test_descriptions_use_plain_words(self):
text = " --expert-cache N R4: experts held in VRAM (default auto)\n --mystery N R7 internal thing T2\n"
rows = {p.name: p for p in P.parse_help(text)}
self.assertNotIn("R4", rows["--expert-cache"].short)
self.assertIn("graphics memory", rows["--expert-cache"].short)
self.assertNotRegex(rows["--mystery"].short, r"\bR\d|\bT\d")
class HintsWrap(Base):
def test_long_key_hints_wrap_instead_of_being_cut(self):
async def case(app, pilot, ctx):
await press(pilot, *("enter",) * 7)
for width in (120, 80, 60, 40):
await pilot.resize_terminal(width, 24)
await pilot.pause(0.25)
hints = app.screen.query_one("#hints")
self.assertGreaterEqual(hints.region.height, 1)
self.assertIn("n next", flat(app), width)
ctx = make_ctx()
ctx.settings.family, ctx.settings.model = "qwen", "IQ3_XXS"
self.run_app(case, ctx)
class InstalledModelFolder(Base):
"""The GUI's installation: weights, pack, picture reader there; the draft layer gone."""
def build(self):
base = Path(os.environ["LOCALAPPDATA"]).parent / "gui"
docs = base / "Documents" / "Strata"
gguf = docs / "Models" / "qwen-IQ3_XXS" / "Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf"
gguf.parent.mkdir(parents=True)
gguf.write_bytes(b"x")
pack = docs / "packs" / "iq3_xxs"
pack.mkdir(parents=True)
mm = docs / "Models" / "mmproj-Qwen3.8-Flash-Next-BF16.gguf"
mm.write_bytes(b"x")
install = Path(os.environ["STRATA_INSTALL_DIR"])
install.mkdir(parents=True, exist_ok=True)
cfg = {"exe": "component:strata-engine", "tokenizer": str(pack), "args": ["--pack", str(pack), "--native", str(gguf), "--mtp", str(docs / "mtp" / "rt"),
"--max-context", "32768", "--kv", "int8"],
"vision": {"mmproj": str(mm), "gpu": False}}
(install / "strata-iq3_xxs.json").write_text(json.dumps(cfg))
return docs
def test_the_folder_starts_where_the_model_is_and_says_what_is_missing(self):
docs = self.build()
ctx = make_ctx()
ctx.settings.family, ctx.settings.model, ctx.settings.vision = "qwen", "IQ3_XXS", "cpu"
async def case(app, pilot, ctx):
await press(pilot, "enter", "enter") # Start -> Model (Enter) -> Folder
self.assertEqual(app.current, "folder")
field = app.screen.query_one("#folderpath")
self.assertEqual(Path(field.value).resolve(), docs.resolve())
shown = flat(app)
self.assertIn("The model is already downloaded", shown)
self.assertIn("Only the draft layer is missing (5.2 GB)", shown)
self.assertNotIn("Needs about", shown)
self.assertNotIn("download the model", shown.lower())
self.run_app(case, ctx)
def test_everything_there_says_already_downloaded(self):
docs = self.build()
(docs / "mtp" / "rt").mkdir(parents=True)
(docs / "mtp" / "rt" / "experts.bin").write_bytes(b"x")
ctx = make_ctx()
ctx.settings.family, ctx.settings.model, ctx.settings.vision = "qwen", "IQ3_XXS", "cpu"
async def case(app, pilot, ctx):
await press(pilot, "enter", "enter")
shown = flat(app)
self.assertIn("Already downloaded", shown)
self.assertIn("Nothing more to download", shown)
# and the final screen does not warn about a download
await press(pilot, *("enter",) * 5, "n", "enter")
self.assertIn("Nothing needs to be downloaded", flat(app))
self.run_app(case, ctx)
if __name__ == "__main__":
unittest.main()