From de1d3ec190b694436622fe90462abed75f722f3e Mon Sep 17 00:00:00 2001 From: Name_TUT Date: Mon, 24 Aug 2026 20:31:42 +0300 Subject: [PATCH] fix(cli): switch Windows console to UTF-8 on startup --- src/cli/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cli/index.ts b/src/cli/index.ts index eec23a6f..c81ddce0 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,4 +1,5 @@ #!/usr/bin/env node +import { execSync } from "node:child_process"; import { isSea } from "node:sea"; import { argv, exit } from "node:process"; import { runAgentCommand } from "./run-agent.js"; @@ -159,7 +160,24 @@ function userArgsFromArgv(): string[] { return argv.slice(2); } +/** + * Windows console defaults to CP866 for Cyrillic, which makes Russian input, + * output and copy/paste turn into mojibake because Node speaks UTF-8. Switch + * the console code page to UTF-8 (65001) at startup. This only changes the + * console's code page тАФ it does NOT touch stdout/stderr streams, so ink and + * readline rendering are unaffected. + */ +function ensureUtf8Console(): void { + if (process.platform !== "win32") return; + try { + execSync("chcp 65001 >nul", { stdio: "ignore" }); + } catch { + // Non-fatal: some hosts disallow changing the code page. + } +} + async function main(): Promise { + ensureUtf8Console(); const [command, ...rest] = userArgsFromArgv(); if (command === "-h" || command === "--help") { printHelp();