Skip to content

Commit 84d0401

Browse files
fix: add encoding="utf-8" to prompt file open() calls in script_runner (Windows CP950) (#607)
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. Co-authored-by: Sergio Sisternes <sergio_sisternes@epam.com>
1 parent 40621bf commit 84d0401

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/apm_cli/core/script_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _auto_compile_prompts(
256256
compiled_prompt_files.append(prompt_file)
257257

258258
# Read the compiled content
259-
with open(compiled_path, "r") as f:
259+
with open(compiled_path, "r", encoding="utf-8") as f:
260260
compiled_content = f.read().strip()
261261

262262
# 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:
916916
# Now ensure compiled directory exists
917917
self.compiled_dir.mkdir(parents=True, exist_ok=True)
918918

919-
with open(prompt_path, "r") as f:
919+
with open(prompt_path, "r", encoding="utf-8") as f:
920920
content = f.read()
921921

922922
# Parse frontmatter and content
@@ -939,7 +939,7 @@ def compile(self, prompt_file: str, params: Dict[str, str]) -> str:
939939
output_path = self.compiled_dir / output_name
940940

941941
# Write compiled content
942-
with open(output_path, "w") as f:
942+
with open(output_path, "w", encoding="utf-8") as f:
943943
f.write(compiled_content)
944944

945945
return str(output_path)

0 commit comments

Comments
 (0)