Routes: the graph tags, the list names - Message paths' split

The Routes tab had it the other way round: names in the graph, hashes
in the row list. Names in the fan read well on one route and fall
apart on several - each label is set above or below its own marker,
so a long one spills across the lanes either side of it, and the very
graph that earns its lanes is the one that can least afford them.

So take the split the Message paths dialog already settled on. In the
fan, every relay is its first hash byte alone - two cells, whatever
the node is called; only the two endpoints stay named. In the rows,
every hop the resolver can place reads as its contact name, in that
node's own hue, and only a hop with no name to show stands in its
hash at the device's path-hash width. Nothing spells the same node
twice: the two bands cross-reference by colour.

Names cost cells a hash chain doesn't, which is what the row's own
horizontal scroll is for - so it now draws the faint edge marks the
key lane and the Message paths rows draw, and clamps where the tail
is actually readable rather than one step short of it, under a right
mark promising a remainder the keys could not reach.

self_key falls out of the route line and its view: the far end is our
name now, not our hash.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-09 04:04:37 -04:00
1 parent 2319653ea0
commit 641286828d
2 files changed
+125 -76

No files matched your search

+73 -46
View File
@@ -26,15 +26,20 @@ the node itself, in full:
offered whenever the node's full key is known.
* **Routes** — the routes we've actually heard the node arrive over, drawn on the shared
route graph (:mod:`~meshterm.ui.pathgraph`) node→us (the inbound direction the packets
travelled, contact on the left, us on the right). Beneath the graph sits the *route
list*: one selectable row per distinct route (the firmware's learned route and the
observed alternatives, the strongest marked ``★ best``), each spelled out through THE
path widget as a single hash-chain line, its bottleneck SNR / sample count / tag hanging
on the line below. ``↑↓`` moves the selection; the picked route lights white in the graph
travelled, contact on the left, us on the right), each relay tagged by its first hash
byte alone — two cells, so the fan reads however many lanes it carries. Beneath the
graph sits the *route list*, where the names live: one selectable row per distinct route
(the firmware's learned route and the observed alternatives, the strongest marked
``★ best``), each spelled out through THE path widget as a single **named** line — a hop
nobody can name standing in its hash — with its bottleneck SNR / sample count / tag
hanging on the line below. The two bands cross-reference by node hue rather than by
spelling the same hex twice; it is the Message paths dialog's split exactly.
``↑↓`` moves the selection; the picked route lights white in the graph
while the rest go grey and every node not on it fades its label to grey, so the graph
reads as *this* route through the fan. A pathline too wide for the lane never wraps —
the highlighted row instead scrolls horizontally (``←→``) to read it to the end; an
unselected long row just ellipsizes. Only *good* routes are drawn — stale evidence and
the highlighted row instead scrolls horizontally (``←→``) under faint ``…`` edge marks
to read it to the end; an unselected long row just ellipsizes. Only *good* routes are
drawn — stale evidence and
far-weaker outliers are dropped, so the list is the routes worth trusting rather than
every chain ever heard. Enter on a route arms a trace on it (nothing transmits here — it
opens the trace screen loaded with that path); when there is no route evidence to list, a
@@ -73,7 +78,7 @@ from rich.cells import cell_len
from rich.text import Text
from ..core.geo import EARTH_RADIUS_KM, usable_fix
from ..core.models import NODE_TYPE_LABELS, Contact, utcnow
from ..core.models import LOCAL_DEVICE_LABEL, NODE_TYPE_LABELS, Contact, utcnow
from ..platforms import Platform, on_platform
from .mapcanvas import RGB
from .minimap import MiniMap
@@ -965,10 +970,16 @@ class NodeDetailScreen(Screen):
go fully brand, since here the colour *is* the content. The trailing ``…`` is the
app-wide opens-further-prompts mark: Enter on the row arms a trace on it. The
pathline never hop-wraps — it is one line, cropped: the highlighted row rides
:attr:`_hshift` (``←→``, see :meth:`handle`) so a hash chain wider than the lane can
still be read to its end, while every other row (and the context line under any row)
just ellipsizes. The context — bottleneck SNR, sample count, the ``★ best`` /
``device route`` tag — is dropped entirely when a route earns none of it.
:attr:`_hshift` (``←→``, see :meth:`handle`) so a named chain wider than the lane can
still be read to its end, under a faint :data:`_MORE_MARK` at whichever edge the line
continues past — the same window the Info tab's key lane scrolls in, and the same one
the Message paths rows do. That scroll is what buys the row its *names*
(:func:`_route_line`): a hop chain spelled out in places outruns a lane far sooner
than one spelled in hash bytes, and the answer is to read it, not to shorten it. Every
other row (and the context line under any row) just ellipsizes — only the row you are
on can scroll, and it is the only one whose end you are asking to see. The context —
bottleneck SNR, sample count, the ``★ best`` / ``device route`` tag — is dropped
entirely when a route earns none of it.
"""
indent = _ROUTE_INDENT
avail = max(1, width - indent)
@@ -977,8 +988,25 @@ class NodeDetailScreen(Screen):
marked.append(_OPENS_MARKER, style="muted")
if selected and self._hshift:
total = cell_len(marked.plain)
self._hshift = max(0, min(self._hshift, max(0, total - avail)))
path = crop_cells(marked, self._hshift, avail)
# A scrolled row has given up a cell to its left mark, so its last window spans
# ``avail - 1``; clamp to the first whole step that brings the tail inside it —
# short of that the right mark would still be drawn at the far end, promising a
# remainder the keys can no longer reach. (The key lane clamps the same way.)
steps = -(-max(0, total - (avail - 1)) // _HSCROLL_STEP)
self._hshift = max(0, min(self._hshift, steps * _HSCROLL_STEP))
shift = self._hshift
# The marks are chrome inside the window, not extra width: each costs the lane a
# cell, so the crop is measured after they are known — else the line drawn under a
# right-hand ``…`` would run a cell past the row.
left = 1 if shift else 0
inner = avail - left
right = 1 if shift + inner < total else 0
path = Text()
if left:
path.append(_MORE_MARK, style="muted")
path.append_text(crop_cells(marked, shift, max(1, inner - right)))
if right:
path.append(_MORE_MARK, style="muted")
else:
path = marked
path.no_wrap = True
@@ -1272,7 +1300,6 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
key_of=make_name_key_resolver(contacts, stored_names),
style=route_graph_style,
self_name=self_name,
self_key=self_key,
node_label=label,
name_key=key,
node_known=name is not None,
@@ -1392,38 +1419,42 @@ def _route_line(
resolve, # noqa: ANN001 - NodeResolver, kept loose like the graph callbacks
node_known: bool,
self_name: Optional[str],
self_key: Optional[str],
hash_bytes: int,
) -> tuple[Text, Text]:
"""One route as ``(path, context)`` — the pathline, and the line it hangs its context under.
The whole route reads left to right in the graph's own direction (contact on the left, us
on the right), so the row and the drawn line cross-read. ``path`` is one
:class:`~meshterm.ui.pathline.PathLine` — every hop, endpoints included, shown as its hash
at our own node's path-hash-mode width rather than a resolved name, at the width the
device itself carries per hop, as powerline chips where the terminal can draw them. A hop
the resolver can name keeps the key-derived hue the graph's chips and column colours
already use; a hop nobody can name — and the page's own node, when it has no name — reads
in the app-wide unknown-node grey, exactly as it does in the graph above. ``context`` is
the bottleneck SNR, sample count, and a ``★ best`` / ``device route`` tag marking the
winner and the firmware's learned route — kept off the pathline itself so a long hash
chain never crowds it out, and empty when a route earns none of them.
:class:`~meshterm.ui.pathline.PathLine` drawn exactly as the Message paths dialog draws
its arrivals (JP, 2026-08-09): **hops read as names** — every hop the resolver can place
wears its contact name in that node's key-derived hue, as powerline chips where the
terminal can draw them, and our own end takes the ``you`` white. A hop nobody can name has
no name to show, so it stands in its own hash at the device's path-hash-mode width (the
width the radio itself carries per hop) in the app-wide unknown-node grey — colour being
the "this is a name" signal, exactly as in the graph above. No hop repeats its hash after
its name: the hash bytes are the *graph's* job one band up, and what ties a row to the fan
is the shared node hue rather than a second spelling of the hex.
Names cost cells that hashes don't, which is what the row's horizontal scroll is for (see
:meth:`NodeDetailScreen._route_row_lines`) — the same trade the Message paths rows make,
and the reason a name is worth it: a route reads as places, and the reader pays only for
the one row they are on. ``context`` is the bottleneck SNR, sample count, and a ``★ best``
/ ``device route`` tag marking the winner and the firmware's learned route — kept off the
pathline itself so a long chain never crowds it out, and empty when a route earns none.
"""
hash_bytes = max(hash_bytes, 1) # an unknown mode still needs a real width to slice
def hop_of(hop: str) -> PathHop:
shown = _hop_hash(hop, hop, hash_bytes)
named = resolve(hop)
if named and named != hop:
return PathHop(shown, key=hop, lit_bytes=hash_bytes)
return PathHop(shown) # unknown node: grey whole, no key-derived hue
return PathHop(named, key=hop)
return PathHop(_hop_hash(hop, hop, hash_bytes)) # unknown: its hash, keyless grey
head = _hop_hash(name_key, node_label, hash_bytes)
path = PathLine([
PathHop(head, key=name_key, lit_bytes=hash_bytes) if node_known and name_key
else PathHop(head),
PathHop(node_label, key=name_key) if node_known and name_key
else PathHop(_hop_hash(name_key, node_label, hash_bytes)),
*(hop_of(hop) for hop in reversed(hops_out)),
PathHop(_hop_hash(self_key, self_name or "us", hash_bytes), you=True),
PathHop(self_name or LOCAL_DEVICE_LABEL, you=True),
]).text()
atoms: list[Text] = []
@@ -1516,7 +1547,6 @@ def _routes_view(
key_of,
style,
self_name,
self_key,
node_label,
name_key,
node_known,
@@ -1595,7 +1625,7 @@ def _routes_view(
path, context = _route_line(
node_label, name_key, hops_out, tag, weakest, samples,
resolve=resolve, node_known=node_known,
self_name=self_name, self_key=self_key, hash_bytes=hash_bytes,
self_name=self_name, hash_bytes=hash_bytes,
)
routes.append(_Route(draw=tuple(reversed(hops_out)), spec=spec, path=path, context=context))
@@ -1611,20 +1641,17 @@ def _routes_view(
resolve=resolve, self_name=self_name, source=node_label, type_of=type_of, key_of=key_of
)
# This tab names every node in the graph, not just the two ends. Where the Message paths
# graph tags a relay with only its first hash byte, here each relay wears its resolved
# contact name (its colour is already the name's hue), so the whole route reads as places
# rather than hex; an unidentified relay keeps the byte, the honest most it can be called.
# A contracted cluster wears its own count-and-type label. The two endpoints keep
# route_graph_style's names (target on the left, us on the right).
# The graph labels exactly as the Message paths graph does (JP, 2026-08-09): the two
# endpoints by name, every relay by its first hash byte alone. Names in here were the
# obvious read — until a busy fan drew them: each label is set above or below its own
# marker, and a long name spills across the lanes either side of it. Two cells never can,
# so the fan stays legible however many routes it carries. The row list under it is where
# the names live now, and a relay's byte and its row chip cross-reference by hue rather
# than by spelling the same node twice. A contracted cluster keeps its own count-and-type
# label — it stands for no single hash.
def label_of(node: str) -> Optional[str]:
cluster = clusters.get(node)
if cluster is not None:
return cluster.label
if node in (SRC_NODE, DST_NODE):
return byte_label_of(node)
named = resolve(node)
return named if named and named != node else node[:2]
return cluster.label if cluster is not None else byte_label_of(node)
base_rgb_of = label_rgb_of
+52 -30
View File
@@ -190,50 +190,52 @@ def test_tab_strip_collapses_a_lone_tab_to_a_plain_heading() -> None:
# --- the folded-in route line ---------------------------------------------------
def test_route_line_shows_hashes_not_names() -> None:
"""The pathline runs contact → relays → us, every hop by its hash; the tag trails on context."""
def test_route_line_names_its_hops() -> None:
"""The pathline runs contact → relays → us, every hop it can place by *name* — the
Message paths reading; the tag trails on the context line."""
path, context = _route_line(
"Far", FAR.public_key, ("3d63c6429436",), "device", None, 0,
resolve=make_node_resolver([HUB]), node_known=True,
self_name="Us", self_key=US + "0" * 52, hash_bytes=1,
self_name="Us", hash_bytes=1,
)
line = path.plain
assert line.startswith("f2") # the contact anchors the left, by hash
assert "3d" in line # the relay's first-byte hash
assert "Far" not in line and "Hub" not in line # names are not resolved into the line
assert "aa" in line # our own node anchors the right, by hash
assert line.startswith("Far") # the contact anchors the left, by name
assert "Hub" in line # the relay reads as the contact it is, not as ``3d``
assert "3d" not in line and "f2" not in line # no hop repeats its hash after its name
assert line.rstrip().endswith("Us") # our own node anchors the right
assert context.plain == "device route" # the firmware-route tag, off the pathline itself
def test_route_line_greys_hops_nobody_can_name() -> None:
"""A hop the resolver can name keeps its key-derived hue on the hash; a hop nobody can
name — and a page node with no name — reads in the unknown-node grey, like the graph."""
"""A named hop takes its key-derived hue; a hop nobody can name — and a page node with no
name — stands in its hash in the unknown-node grey, like the graph."""
from meshterm.ui.theme import node_style
path, _context = _route_line(
"f2c24f54551e", FAR.public_key, ("3d63c6429436", "abcd1234ef56"), "", None, 0,
resolve=make_node_resolver([HUB]), node_known=False,
self_name="Us", self_key=US + "0" * 52, hash_bytes=1,
self_name="Us", hash_bytes=1,
)
styles = {path.plain[s.start : s.end]: str(s.style) for s in path.spans}
assert styles.get("ab") == "node.unknown" # no contact names it → grey, no key hue
assert styles.get("ab") == "node.unknown" # no contact names it → its hash, grey
assert styles.get("f2") == "node.unknown" # the nameless page node greys its own hash
hued = {path.plain[s.start : s.end] for s in path.spans
if str(s.style) == node_style("3d63c6429436")}
assert "3d" in hued # the Hub is a named contact, so its hash keeps the hue
assert "Hub" in hued # the Hub is a named contact: its name, in its own hue
def test_route_line_hash_width_follows_our_path_hash_mode() -> None:
"""A device carrying 3-byte routing hashes shows 3-byte hops, not the 1-byte default."""
"""Only the hops with no name to show spend hash cells — and those at the device's own
path-hash width, three bytes here rather than the 1-byte default."""
path, _context = _route_line(
"Far", FAR.public_key, ("3d63c6429436",), "", None, 0,
resolve=make_node_resolver([HUB]), node_known=True,
self_name="Us", self_key=US + "0" * 52, hash_bytes=3,
"f2c24f54551e", FAR.public_key, ("3d63c6429436", "abcd1234ef56"), "", None, 0,
resolve=make_node_resolver([HUB]), node_known=False,
self_name="Us", hash_bytes=3,
)
line = path.plain
assert "f2c24f" in line # the contact's hash at 3 bytes
assert "3d63c6" in line # the relay's hash at 3 bytes
assert "aaaaaa" in line # our own node's hash at 3 bytes
assert "f2c24f" in line # the nameless page node, at 3 bytes
assert "abcd12" in line # the unnamed relay, at 3 bytes
assert "Hub" in line and "3d63c6" not in line # the named one never spends them
def test_route_line_marks_the_best_route_and_its_context() -> None:
@@ -241,7 +243,7 @@ def test_route_line_marks_the_best_route_and_its_context() -> None:
_path, context = _route_line(
"Far", FAR.public_key, ("3d63c6429436",), "best", 6.5, 4,
resolve=make_node_resolver([HUB]), node_known=True,
self_name="Us", self_key=US + "0" * 52, hash_bytes=1,
self_name="Us", hash_bytes=1,
)
line = context.plain
assert "★ best" in line and "weakest" in line and "6.5" in line and "4×" in line
@@ -252,10 +254,10 @@ def test_route_line_direct_route_has_no_relay() -> None:
path, _context = _route_line(
"Far", FAR.public_key, (), "best", None, 0,
resolve=make_node_resolver([HUB]), node_known=True,
self_name="Us", self_key=US + "0" * 52, hash_bytes=1,
self_name="Us", hash_bytes=1,
)
line = path.plain
assert "f2" in line and "aa" in line and "→" in line
assert "Far" in line and "Us" in line and "→" in line
# --- the routes view (list + graph callbacks) -----------------------------------
@@ -283,7 +285,7 @@ def _view(topo, suggested, device_route, target, node_label, contacts, name_key=
resolve=make_node_resolver(contacts),
type_of=make_node_type_resolver(contacts),
key_of=make_name_key_resolver(contacts),
style=route_graph_style, self_name="Us", self_key=US + "0" * 52,
style=route_graph_style, self_name="Us",
node_label=node_label,
name_key=name_key or (target + "0" * 52),
node_known=True,
@@ -305,7 +307,6 @@ def test_routes_view_draws_evidence_and_notes_its_absence() -> None:
empty, empty.scenarios("f2c24f54551e"), None, None, "f2c24f54551e", "f2c24f54551e", 1,
resolve=make_node_resolver([FAR]), type_of=make_node_type_resolver([FAR]),
key_of=make_name_key_resolver([FAR]), style=route_graph_style, self_name="Us",
self_key=US + "0" * 52,
node_label="Far", name_key=FAR.public_key,
node_known=True,
hash_bytes=1,
@@ -321,15 +322,19 @@ def test_routes_view_puts_the_contact_on_the_left_and_us_on_the_right() -> None:
assert view.label_of(SRC_NODE) == "Far" # the left endpoint is the target contact
assert view.glyph_of(DST_NODE)[0] == "★" # the right endpoint is our own star
assert view.label_of(DST_NODE) == "Us" # …labelled as us
# This page names every node: a known relay reads by its contact name, not its hash byte.
assert view.label_of("3d63c6429436") == "Hub"
def test_routes_view_relay_falls_back_to_the_hash_byte_when_unnamed() -> None:
"""A relay no contact can name keeps the honest first-byte tag rather than a blank."""
def test_routes_view_tags_every_relay_with_its_hash_byte_alone() -> None:
"""Only the two endpoints are named in the graph — a relay wears its first hash byte
whether or not a contact can name it, so a label never outgrows two cells and spills
across the lanes it sits between (the Message paths graph's rule exactly)."""
topo = _topo_with_route()
view = _view(topo, None, ("abcd1234ef56",), "f2c24f54551e", "Far", [FAR])
assert view.label_of("abcd1234ef56") == "ab" # unnamed → its first hash byte
view = _view(topo, topo.suggested("f2c24f54551e"), ("3d63c6429436",),
"f2c24f54551e", "Far", [HUB, FAR])
assert view.label_of("3d63c6429436") == "3d" # the Hub is a known contact — still ``3d``
unnamed = _view(topo, None, ("abcd1234ef56",), "f2c24f54551e", "Far", [FAR])
assert unnamed.label_of("abcd1234ef56") == "ab" # and one nobody can name reads the same
def test_routes_view_target_wears_its_node_type_glyph() -> None:
@@ -710,15 +715,32 @@ def test_node_detail_screen_hscrolls_the_selected_pathline() -> None:
assert "f2 00 01 02" in body # unscrolled, the chain's start shows
assert "←→ scroll" in screen.footer_hint # the overflow earns the footer atom
row = next(l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯"))
assert row.rstrip().endswith("…") # the right edge marks the remainder, before any scroll
screen.handle("right")
screen.handle("right")
body = _plain(screen.render_body(72))
assert "f2 00 01 02" not in body # the view has shifted away from the start
row = next(l for l in body.splitlines() if l.startswith("❯"))
assert row.startswith("❯ …") # …and now a mark says the line continues behind us, too
screen.handle("left")
body = _plain(screen.render_body(72))
assert "f2 00 01 02" not in body # one step back, still short of the start
for _ in range(20): # run the scroll to its stop
screen.handle("right")
row = next(l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯"))
# The clamp lands where the tail is actually readable: the line's own end — the last hop
# and the opens-marker — is on screen rather than cropped behind a right-hand edge mark
# promising a remainder the keys can no longer reach. Only the left mark is left drawn.
assert row.rstrip().endswith("aa …") and row.count("…") == 2
screen.handle("right") # …and the stop holds: nothing moves past it
assert next(
l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯")
) == row
screen.handle("down") # onto route 1 — abandons route 0's scroll, short row can't scroll
screen.render_body(72)
assert "←→ scroll" not in screen.footer_hint # route 1's short pathline earns no hint