diff --git a/Src/PeasyAI/src/core/services/compilation.py b/Src/PeasyAI/src/core/services/compilation.py index 8b83c9e92..049c456cd 100644 --- a/Src/PeasyAI/src/core/services/compilation.py +++ b/Src/PeasyAI/src/core/services/compilation.py @@ -5,6 +5,7 @@ This service is UI-agnostic. """ +import os import subprocess import logging import traceback @@ -85,13 +86,20 @@ def compile(self, project_path: str) -> CompilationResult: return_code=-1, ) - # Run P compiler + # Run P compiler. Default to collecting-mode (`P_COMPILER_COLLECT_ERRORS=1`) + # so a project with N independent type errors produces all N diagnostics + # in one compile, letting PeasyAI's fix loop converge in N/k iterations + # instead of N. setdefault preserves an explicit user override (set the + # env var to "0" or "false" in the parent shell to keep strict mode). + env = os.environ.copy() + env.setdefault("P_COMPILER_COLLECT_ERRORS", "1") result = subprocess.run( ['p', 'compile'], capture_output=True, cwd=project_path, text=True, timeout=300, # 5 minute timeout + env=env, ) # Check for success diff --git a/Src/PeasyAI/src/core/services/generation.py b/Src/PeasyAI/src/core/services/generation.py index 02ddca39c..2c6a4026f 100644 --- a/Src/PeasyAI/src/core/services/generation.py +++ b/Src/PeasyAI/src/core/services/generation.py @@ -1442,12 +1442,17 @@ def _compile_check_candidates( env = ensure_environment() if env.is_valid and env.p_compiler_path: import subprocess + # Default to collecting-mode compilation (see + # core/services/compilation.py for full rationale). + subprocess_env = os.environ.copy() + subprocess_env.setdefault("P_COMPILER_COLLECT_ERRORS", "1") result = subprocess.run( [env.p_compiler_path, "compile"], cwd=project_path, capture_output=True, text=True, timeout=30, + env=subprocess_env, ) if result.returncode == 0: logger.info(f" Candidate compiles successfully (+{COMPILE_BONUS} bonus)") diff --git a/Src/PeasyAI/src/utils/compile_utils.py b/Src/PeasyAI/src/utils/compile_utils.py index 0bf566316..ac7920d6b 100644 --- a/Src/PeasyAI/src/utils/compile_utils.py +++ b/Src/PeasyAI/src/utils/compile_utils.py @@ -36,7 +36,16 @@ def try_compile(ppath, captured_streams_output_dir): flags = ['-pf', ppath, "-o", str(p.parent)] if p.is_file() else [] final_cmd_arr = ['p', 'compile', *flags] - result = subprocess.run(final_cmd_arr, capture_output=True, cwd=ppath if not p.is_file() else None) + # Default to collecting-mode compilation (see compilation.py for full rationale). + # setdefault preserves an explicit user override. + env = os.environ.copy() + env.setdefault("P_COMPILER_COLLECT_ERRORS", "1") + result = subprocess.run( + final_cmd_arr, + capture_output=True, + cwd=ppath if not p.is_file() else None, + env=env, + ) out_dir = f"{captured_streams_output_dir}/compile" os.makedirs(out_dir, exist_ok=True)