From c2620a5b269db75fcadb772e3ae5250886e8814c Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Fri, 4 Sep 2026 02:35:41 +0200 Subject: fix(node): make init, node.toml editing and CLI output work on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by running the daemon on Windows for the first time: - `meshbay-node init` wrote `unlock_file = "C:\Users\..."`, and attach_group / add_root write `path = "C:\..."` — a raw Windows path in a TOML basic string is a parse error (`\U`, `\a`, ... are escape sequences), so the config would not load. All now write `Path(...).as_posix()`; pathlib reads the forward-slash form fine on Windows. - any `print()` carrying a `->` arrow or em dash (the CLI help and messages are full of them) raised UnicodeEncodeError on a cp1252 console and took the command down. New `platform.force_utf8_stdio()` reconfigures stdout/stderr to UTF-8, called at the top of `main()`. Verified on Windows: init writes parseable LF node.toml, the keystore Argon2-decrypts, the loopback control API binds 127.0.0.1, and `_update_node_toml` reads a CRLF file and rewrites it LF-only with its standalone comments intact. Two regression tests added in test_ops.py. Co-Authored-By: Claude Sonnet 5 --- packages/meshbay-node/src/meshbay_node/platform.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'packages/meshbay-node/src/meshbay_node/platform.py') diff --git a/packages/meshbay-node/src/meshbay_node/platform.py b/packages/meshbay-node/src/meshbay_node/platform.py index 4bd8e35..80aa6ae 100644 --- a/packages/meshbay-node/src/meshbay_node/platform.py +++ b/packages/meshbay-node/src/meshbay_node/platform.py @@ -6,6 +6,24 @@ import shutil import sys from pathlib import Path +# ── Console ────────────────────────────────────────────────────────────────── + + +def force_utf8_stdio() -> None: + """ + Make stdout/stderr UTF-8. A Windows console is cp1252 by default, so any + ``print()`` carrying a character outside it — the ``->`` arrows and em + dashes the CLI help and messages are full of — raises UnicodeEncodeError + and takes the command down with it. No effect where the streams are + already UTF-8 or cannot be reconfigured. + """ + for stream in (sys.stdout, sys.stderr): + try: + stream.reconfigure(encoding="utf-8") + except (AttributeError, ValueError, OSError): + pass + + # ── Event loop ─────────────────────────────────────────────────────────────── -- cgit v1.2.3