From 64e6c2f5f59f21629fe5b12fe2c8d968c114a3ac Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Mon, 24 Aug 2026 15:04:11 +0300 Subject: [PATCH] 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 --- .claude/skills/repo-handoff/SKILL.md | 2 +- .claude/skills/repository-bootstrap/SKILL.md | 2 +- src/stewardship/bootstrap.py | 2 +- src/stewardship/cli.py | 17 +++++++++++++++++ src/stewardship/skills_content.py | 4 ++-- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.claude/skills/repo-handoff/SKILL.md b/.claude/skills/repo-handoff/SKILL.md index 2908281..55ee1b9 100644 --- a/.claude/skills/repo-handoff/SKILL.md +++ b/.claude/skills/repo-handoff/SKILL.md @@ -6,7 +6,7 @@ description: Produce a minimal, intent-scoped context handoff for a repository u # repo-handoff Thin wrapper around `repoctl context`. Do not read the full repository or the full KDB -by hand when this skill applies — let `repoctl` perform the selection. +by hand when this skill applies - let `repoctl` perform the selection. ## Procedure diff --git a/.claude/skills/repository-bootstrap/SKILL.md b/.claude/skills/repository-bootstrap/SKILL.md index 0aa0b2f..5f226ed 100644 --- a/.claude/skills/repository-bootstrap/SKILL.md +++ b/.claude/skills/repository-bootstrap/SKILL.md @@ -6,7 +6,7 @@ description: Bootstrap a new repository into Repository Stewardship using repoct # repository-bootstrap Thin wrapper around `repoctl init`. Do not reimplement classification, template -rendering or validation here — call the CLI and explain its output. +rendering or validation here - call the CLI and explain its output. ## Procedure diff --git a/src/stewardship/bootstrap.py b/src/stewardship/bootstrap.py index 1781a8a..80389ae 100644 --- a/src/stewardship/bootstrap.py +++ b/src/stewardship/bootstrap.py @@ -1,6 +1,6 @@ """`repoctl init`: plan-then-apply bootstrap of a new repository. -Content roots are declared in the contract but their directories are not created — +Content roots are declared in the contract but their directories are not created - this repository's self-hosting rule forbids placeholder directories and fictional domain artifacts. `init` never commits, pushes or creates a remote. """ diff --git a/src/stewardship/cli.py b/src/stewardship/cli.py index 90db008..50648b8 100644 --- a/src/stewardship/cli.py +++ b/src/stewardship/cli.py @@ -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: diff --git a/src/stewardship/skills_content.py b/src/stewardship/skills_content.py index db481d6..301acaa 100644 --- a/src/stewardship/skills_content.py +++ b/src/stewardship/skills_content.py @@ -14,7 +14,7 @@ description: Bootstrap a new repository into Repository Stewardship using repoct # repository-bootstrap Thin wrapper around `repoctl init`. Do not reimplement classification, template -rendering or validation here — call the CLI and explain its output. +rendering or validation here - call the CLI and explain its output. ## Procedure @@ -68,7 +68,7 @@ description: Produce a minimal, intent-scoped context handoff for a repository u # repo-handoff Thin wrapper around `repoctl context`. Do not read the full repository or the full KDB -by hand when this skill applies — let `repoctl` perform the selection. +by hand when this skill applies - let `repoctl` perform the selection. ## Procedure