From 76efefb407b1576b1f1a88dcff6f8849c34d33f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A8=B1=E5=85=83=E8=B1=AA?= <146086744+edenfunf@users.noreply.github.com> Date: Tue, 7 Apr 2026 14:01:30 +0800 Subject: [PATCH] fix: add encoding="utf-8" to prompt file open() calls in script_runner (Windows CP950) PromptCompiler.compile() and _resolve_prompt_file() open .prompt.md files with plain open() which defaults to the system locale encoding. On Windows systems set to CP950/CP936/CP932 (Chinese/Japanese/Korean), a UTF-8 encoded prompt file containing any multibyte character causes: UnicodeDecodeError: 'cp950' codec can't decode byte 0x8b in position 12 Three open() calls were missing explicit encoding: - compiled_path read in ScriptRunner._execute_script - prompt_path read in PromptCompiler.compile - output_path write in PromptCompiler.compile Adding encoding="utf-8" to all three matches the behaviour of the rest of the codebase and fixes the crash for any non-UTF-8 Windows locale. --- src/apm_cli/core/script_runner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apm_cli/core/script_runner.py b/src/apm_cli/core/script_runner.py index 87798c5c..fcb919fd 100644 --- a/src/apm_cli/core/script_runner.py +++ b/src/apm_cli/core/script_runner.py @@ -256,7 +256,7 @@ def _auto_compile_prompts( compiled_prompt_files.append(prompt_file) # Read the compiled content - with open(compiled_path, "r") as f: + with open(compiled_path, "r", encoding="utf-8") as f: compiled_content = f.read().strip() # Check if this is a runtime command (copilot, codex, llm) before transformation @@ -916,7 +916,7 @@ def compile(self, prompt_file: str, params: Dict[str, str]) -> str: # Now ensure compiled directory exists self.compiled_dir.mkdir(parents=True, exist_ok=True) - with open(prompt_path, "r") as f: + with open(prompt_path, "r", encoding="utf-8") as f: content = f.read() # Parse frontmatter and content @@ -939,7 +939,7 @@ def compile(self, prompt_file: str, params: Dict[str, str]) -> str: output_path = self.compiled_dir / output_name # Write compiled content - with open(output_path, "w") as f: + with open(output_path, "w", encoding="utf-8") as f: f.write(compiled_content) return str(output_path)