fix(input): invoke codex exec with stdin

This commit is contained in:
2025-10-15 17:31:52 -05:00
parent 6a5ce586eb
commit 92fc6e5d68

View File

@@ -184,23 +184,26 @@ def slugify(component: str) -> str:
return "-".join(parts)
def run_codex(prompt_path: Path, output_path: Path) -> None:
"""Execute the Codex CLI."""
def run_codex(prompt_text: str, output_path: Path) -> None:
"""Execute the Codex CLI with the provided prompt text."""
output_path.parent.mkdir(parents=True, exist_ok=True)
command = [
"codex",
"prompt",
"--input",
str(prompt_path),
"--output",
"exec",
"-",
"--output-last-message",
str(output_path),
"--format",
"markdown",
"--skip-git-repo-check",
"--sandbox",
"read-only",
]
logging.info("Running Codex CLI command: %s", " ".join(command))
try:
subprocess.run(
command,
input=prompt_text.encode("utf-8"),
check=True,
timeout=CODEX_TIMEOUT_SECONDS,
env=os.environ.copy(),
@@ -287,11 +290,8 @@ def normalize_job_description(job_file: Path) -> NormalizedJobDescription:
with TemporaryDirectory() as tmp_dir_str:
tmp_dir = Path(tmp_dir_str)
prompt_path = tmp_dir / "normalize_prompt.md"
prompt_path.write_text(prompt_text, encoding="utf-8")
output_path = tmp_dir / "normalize_output.md"
run_codex(prompt_path, output_path)
run_codex(prompt_text, output_path)
normalized_text = output_path.read_text(encoding="utf-8").strip()
return parse_normalized_output(normalized_text)
@@ -342,11 +342,8 @@ def process_job(job_file: Path) -> None:
with TemporaryDirectory() as tmp_dir_str:
tmp_dir = Path(tmp_dir_str)
prompt_path = tmp_dir / "prompt.md"
prompt_path.write_text(prompt_text, encoding="utf-8")
output_path = tmp_dir / "codex_output.md"
run_codex(prompt_path, output_path)
run_codex(prompt_text, output_path)
generated_output = out_dir / output_filename
counter = 1