@@ -143,8 +143,8 @@ private CodexCliResult runProcess(String stdin, String... args) {
143143 long startNanos = System .nanoTime ();
144144 try {
145145 int exitCode = executor .execute (cmd );
146- String out = stdout . toString ( ).trim ();
147- String err = stderr . toString ( ).trim ();
146+ String out = utf8 ( stdout ).trim ();
147+ String err = utf8 ( stderr ).trim ();
148148 log .debug ("codex CLI executed: exitCode={}, stdout.len={}" , exitCode , out .length ());
149149 if (watchdog .killedProcess ()) {
150150 return new CodexCliResult (-1 , out , "codex CLI timed out after " + timeoutMs + " ms\n " + err );
@@ -157,8 +157,8 @@ private CodexCliResult runProcess(String stdin, String... args) {
157157 // with the real exit code instead of discarding the output. The
158158 // deadline check makes the timeout verdict race-free even when
159159 // {@code watchdog.killedProcess()} has not observed the kill yet.
160- String out = stdout . toString ( ).trim ();
161- String err = stderr . toString ( ).trim ();
160+ String out = utf8 ( stdout ).trim ();
161+ String err = utf8 ( stderr ).trim ();
162162 boolean timedOut = watchdog .killedProcess ()
163163 || System .nanoTime () - startNanos >= timeoutMs * 1_000_000L ;
164164 if (timedOut ) {
@@ -172,6 +172,21 @@ private CodexCliResult runProcess(String stdin, String... args) {
172172 }
173173 }
174174
175+ /**
176+ * Decodes the captured buffer as UTF-8 — the CLIs emit UTF-8 regardless of
177+ * platform, and the platform default charset would mojibake the output on
178+ * GBK-default Windows. {@code ByteArrayOutputStream.toString(Charset)}
179+ * only exists since Java 10, so the JDK 8 line goes through the String
180+ * name variant with an unreachable fallback (UTF-8 is guaranteed).
181+ */
182+ private static String utf8 (ByteArrayOutputStream buffer ) {
183+ try {
184+ return buffer .toString ("UTF-8" );
185+ } catch (java .io .UnsupportedEncodingException e ) {
186+ return buffer .toString ();
187+ }
188+ }
189+
175190 /**
176191 * Lightweight reachability probe used by {@code CodexClient#isAvailable()}.
177192 *
0 commit comments