fix: force UTF-8 stdout/stderr in repoctl and drop non-ASCII em dashes

End-to-end smoke testing of `init` and `adopt` (plan -> approve -> apply -> verify)
via subprocess surfaced a real portability bug: on Windows, sys.stdout defaults to
the console codepage rather than UTF-8 when not attached to a UTF-8 terminal, so
machine YAML/JSON output containing non-ASCII characters (an em dash in generated
skill/docstring text) could fail to decode for downstream consumers. repoctl now
reconfigures stdout/stderr to UTF-8 unconditionally in main(), and the offending
em dashes are replaced with ASCII hyphens so generated file content is unaffected
either way.

Verified via manual CLI smoke tests: full init and adopt flows (including baseline
re-check, plan-hash approval, collision rejection on re-apply, and preservation of
profiles-source/, profiles/ and legacy kdb.yaml) work end to end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Alexander Baranov
2026-08-24 15:04:11 +03:00
co-authored by Claude Sonnet 5
parent 7286322c83
commit 64e6c2f5f5
5 changed files with 22 additions and 5 deletions
+17
View File
@@ -316,7 +316,24 @@ def build_parser() -> argparse.ArgumentParser:
return parser
def _force_utf8_streams() -> None:
"""Force UTF-8 stdout/stderr regardless of the host locale/console codepage.
Machine output (YAML/JSON) must be reliably UTF-8 for downstream parsers; on
Windows, sys.stdout otherwise defaults to the console codepage when not attached
to a UTF-8 terminal, which can corrupt or fail to decode non-ASCII content.
"""
for stream in (sys.stdout, sys.stderr):
reconfigure = getattr(stream, "reconfigure", None)
if callable(reconfigure):
try:
reconfigure(encoding="utf-8")
except (ValueError, OSError):
pass
def main(argv: list[str] | None = None) -> int:
_force_utf8_streams()
parser = build_parser()
args = parser.parse_args(argv)
try: