From 51969050da02917df048b6ed8f9c1654feeea326 Mon Sep 17 00:00:00 2001 From: K7ZVX Date: Tue, 5 May 2026 07:11:08 +0000 Subject: [PATCH] fix: Replace deleted REGION_CONTEXT with config method, replace hardcoded city map with config aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Line 763: REGION_CONTEXT.get() → self._region_context() (same method used elsewhere) - Deleted _CITY_TO_REGION hardcoded dict - Scope detection now uses config aliases/cities from RegionAnchor - Fixed Sun Valley/Ketchum geography (was Central ID, should be South Central ID) Co-Authored-By: Claude Opus 4.5 --- meshai/mesh_reporter.py | 2 +- meshai/router.py | 63 +++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/meshai/mesh_reporter.py b/meshai/mesh_reporter.py index a78d3b8..9e1ab1d 100644 --- a/meshai/mesh_reporter.py +++ b/meshai/mesh_reporter.py @@ -760,7 +760,7 @@ class MeshReporter: f"ID: !{node.node_num:08x} (dec: {node.node_num})", f"Hardware: {node.hw_model or 'Unknown'}", f"Role: {node.role} ({'Infrastructure' if node.is_infrastructure else 'Client'})", - f"Region: {node.region or 'Unknown'}{' — ' + REGION_CONTEXT.get(node.region, '') if node.region and REGION_CONTEXT.get(node.region) else ''} / Locality: {node.locality or 'Unknown'}", + f"Region: {node.region or 'Unknown'}{' — ' + self._region_context(node.region) if node.region and self._region_context(node.region) else ''} / Locality: {node.locality or 'Unknown'}", ] if node.latitude and node.longitude: diff --git a/meshai/router.py b/meshai/router.py index ab1a352..527332f 100644 --- a/meshai/router.py +++ b/meshai/router.py @@ -88,40 +88,7 @@ _MESH_PHRASES = [ ] # City name to region mapping (hardcoded fallback) -_CITY_TO_REGION = { - # Idaho - "twin falls": "South Central ID", - "boise": "South Western ID", - "nampa": "South Western ID", - "meridian": "South Western ID", - "caldwell": "South Western ID", - "idaho falls": "South Eastern ID", - "pocatello": "South Eastern ID", - "coeur d'alene": "Northern ID", - "cda": "Northern ID", - "post falls": "Northern ID", - "moscow": "Northern ID", - "lewiston": "Northern ID", - "salmon": "Central ID", - "sun valley": "Central ID", - "ketchum": "Central ID", - # Utah - "ogden": "Northern UT", - "logan": "Northern UT", - "salt lake": "Central UT", - "salt lake city": "Central UT", - "slc": "Central UT", - "provo": "Central UT", - "orem": "Central UT", - "vernal": "Eastern UT", - "moab": "Eastern UT", - "price": "Eastern UT", - "tooele": "Western UT", - "wendover": "Western UT", - "st george": "Southern UT", - "st. george": "Southern UT", - "cedar city": "Southern UT", -} +# City/alias mapping now built from config - see _build_alias_map() # Mesh awareness instruction for LLM # Mesh awareness instruction for LLM @@ -243,6 +210,28 @@ class MessageRouter: self._region_abbrevs = _build_region_abbreviations(region_names) logger.debug(f"Built region abbreviations: {self._region_abbrevs}") + # Build city/alias mapping from config + self._alias_map = self._build_alias_map() + if self._alias_map: + logger.debug(f"Built alias map with {len(self._alias_map)} entries") + + def _build_alias_map(self) -> dict[str, str]: + """Build city/alias to region mapping from config.""" + alias_map = {} + if self.config.mesh_intelligence and self.config.mesh_intelligence.regions: + for region in self.config.mesh_intelligence.regions: + # Add aliases + for alias in (getattr(region, 'aliases', []) or []): + alias_map[alias.lower()] = region.name + # Add cities + for city in (getattr(region, 'cities', []) or []): + alias_map[city.lower()] = region.name + # Add local_name + local = getattr(region, 'local_name', '') or '' + if local: + alias_map[local.lower()] = region.name + return alias_map + def should_respond(self, message: MeshMessage) -> bool: """Determine if we should respond to this message. @@ -418,9 +407,9 @@ class MessageRouter: if re.search(pattern, msg_lower): return ("region", region_name) - # 2. Check city names - for city, region_name in _CITY_TO_REGION.items(): - if city in msg_lower: + # 2. Check city names and aliases from config + for alias, region_name in self._alias_map.items(): + if alias in msg_lower: return ("region", region_name) # 3. Full region name matching (SORTED BY LENGTH - longest first)