From f5c172456707023ed5d793db50387251063041e1 Mon Sep 17 00:00:00 2001 From: "Matt Johnson (via Claude)" Date: Wed, 10 Jun 2026 02:23:22 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20nws=20locations=20truncation=20=E2=80=94?= =?UTF-8?q?=20configurable=20word-boundary=20cap=20(default=20120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace hardcoded 40-char locations cap with adapter_config key nws.locations_max_chars (default 120). Truncation now uses word-boundary split with ellipsis, matching the swpc _trunc pattern. Co-Authored-By: Claude Opus 4.6 --- meshai/adapter_config/defaults.py | 5 +++++ meshai/central/nws_handler.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meshai/adapter_config/defaults.py b/meshai/adapter_config/defaults.py index e5ada38..4157a0d 100644 --- a/meshai/adapter_config/defaults.py +++ b/meshai/adapter_config/defaults.py @@ -571,6 +571,11 @@ REGISTRY: dict[tuple[str, str], dict[str, Any]] = { "type": "int", "description": "Allow re-broadcast of the same CAP id after this many seconds (the nws_handler relaxes its dedup gate past this point and uses an Active: prefix).", }, + ("nws", "locations_max_chars"): { + "default": 120, + "type": "int", + "description": "Maximum characters for the locations field on line 4 of NWS wire. Truncates at word boundary.", + }, # ================================================================= # AVALANCHE -- 1 setting (min danger level broadcast floor) diff --git a/meshai/central/nws_handler.py b/meshai/central/nws_handler.py index e541327..6fbd956 100644 --- a/meshai/central/nws_handler.py +++ b/meshai/central/nws_handler.py @@ -384,8 +384,12 @@ def _render(*, event_type, area_desc, geocoder_city, county, state, compass, speed_mph = _parse_motion(params) motion = f"Moving {compass} {speed_mph} mph" if compass and speed_mph else "" locations = (desc.get("locations") or "").rstrip("., ") - if len(locations) > 40: - locations = locations[:37] + "..." + _loc_limit = int(adapter_config.nws.locations_max_chars) + if len(locations) > _loc_limit: + cut = locations[:_loc_limit].rsplit(" ", 1)[0] + if not cut: + cut = locations[:_loc_limit] + locations = cut + "\u2026" if motion and locations: line4 = f"{motion} — {locations}" elif motion: