From cf5e95579ca221f0bf2183b7bee9c033e8c6d680 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Wed, 6 May 2026 21:04:59 +0200 Subject: [PATCH] feat(console): accept 'direct' keyword in change_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting a contact's path to Direct means 0 hops with an empty path body. The hex parser had no way to express that — empty/non-hex input always failed validation, and reset_path forces Flood instead. Add a 'direct' keyword that bypasses hex parsing and sends an empty path with hash_size=1, producing out_path_len=0 (Direct). Update the usage block and the help entry to document it and to point at reset_path for the Flood case. Co-Authored-By: Claude Opus 4.7 --- app/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 614f4bd..0fb4499 100644 --- a/app/main.py +++ b/app/main.py @@ -845,7 +845,13 @@ def _execute_console_command(args: list) -> str: elif cmd == 'change_path' and len(args) >= 3: name = args[1] # Recombine remaining args so space-separated input ("d1 90 05 54") works - raw = ' '.join(args[2:]) + raw = ' '.join(args[2:]).strip() + # Special keyword: 'direct' sets the path to Direct (0 hops, empty path) + if raw.lower() == 'direct': + result = device_manager.change_path(name, '', hash_size=1) + if result.get('success'): + return result.get('message', 'OK') + return f"Error: {result.get('error')}" if ',' in raw: chunks = [c.strip() for c in raw.split(',') if c.strip()] first_len = len(chunks[0]) if chunks else 0 @@ -869,11 +875,13 @@ def _execute_console_command(args: list) -> str: return f"Error: {result.get('error')}" elif cmd == 'change_path': - return ("Usage: change_path \n" + return ("Usage: change_path \n" " hops: comma-separated hex, e.g. d1,90,05,54 (1-byte hops)\n" " 5e34,d1ac (2-byte hops)\n" " 5e346e,d1ac2c (3-byte hops)\n" - " Spaces or continuous hex also accepted.") + " direct: set path to Direct (0 hops)\n" + " Spaces or continuous hex also accepted.\n" + " (Use reset_path to set the path to Flood.)") elif cmd == 'advert_path' and len(args) >= 2: name = ' '.join(args[1:]) @@ -1274,7 +1282,7 @@ def _execute_console_command(args: list) -> str: " path — Show path to contact\n" " disc_path — Discover new path\n" " reset_path — Reset path to flood\n" - " change_path — Change path (e.g. d1,90,05,54 or 5e34,d1ac)\n" + " change_path — Change path (e.g. d1,90,05,54 or direct)\n" " advert_path — Get path from advert\n" " share_contact — Share contact with mesh\n" " export_contact — Export contact URI\n"