refactor(input): bake codex cli runtime

This commit is contained in:
2025-10-15 17:29:06 -05:00
parent 5cd30ef5f2
commit 6a5ce586eb
5 changed files with 32 additions and 39 deletions

View File

@@ -13,7 +13,6 @@ from __future__ import annotations
import logging
import os
import shlex
import shutil
import subprocess
import time
@@ -32,17 +31,9 @@ TEMPLATES_DIR = Path("/templates")
TEMPLATE_CACHE = Path("/tmp/templates")
PROMPT_TEMPLATE = TEMPLATES_DIR / "ResumeCustomizerPrompt.md"
PROMPT_TEMPLATE_EXAMPLE = TEMPLATES_DIR / "ResumeCustomizerPrompt.md.example"
NORMALIZER_TEMPLATE = Path('/app/JobDescriptionNormalizerPrompt.md')
NORMALIZER_TEMPLATE = Path("/app/JobDescriptionNormalizerPrompt.md")
POLL_INTERVAL_SECONDS = int(os.environ.get("POLL_INTERVAL_SECONDS", "5"))
CODEX_COMMAND_TEMPLATE = os.environ.get(
"CODEX_COMMAND_TEMPLATE",
"codex prompt --input {prompt} --output {output} --format markdown",
)
CODEX_NORMALIZER_COMMAND_TEMPLATE = os.environ.get(
"CODEX_NORMALIZER_COMMAND_TEMPLATE",
CODEX_COMMAND_TEMPLATE,
)
CODEX_TIMEOUT_SECONDS = int(os.environ.get("CODEX_TIMEOUT_SECONDS", "600"))
RESOLVED_PROMPT_TEMPLATE: Path | None = None
@@ -193,20 +184,19 @@ def slugify(component: str) -> str:
return "-".join(parts)
def run_codex(prompt_path: Path, output_path: Path, command_template: str) -> None:
"""Execute the Codex CLI using the provided command template."""
command_text = command_template.format(
prompt=str(prompt_path),
output=str(output_path),
)
logging.info("Running Codex CLI command: %s", command_text)
try:
command = shlex.split(command_text)
except ValueError as exc:
raise FatalConfigurationError(
f"Unable to parse Codex command template into arguments: {exc}"
) from exc
def run_codex(prompt_path: Path, output_path: Path) -> None:
"""Execute the Codex CLI."""
command = [
"codex",
"prompt",
"--input",
str(prompt_path),
"--output",
str(output_path),
"--format",
"markdown",
]
logging.info("Running Codex CLI command: %s", " ".join(command))
try:
subprocess.run(
@@ -217,7 +207,7 @@ def run_codex(prompt_path: Path, output_path: Path, command_template: str) -> No
)
except FileNotFoundError as exc:
raise FatalConfigurationError(
f"Executable not found while running Codex CLI command: {command[0]}"
"Codex CLI executable 'codex' not found in PATH"
) from exc
except subprocess.TimeoutExpired as exc:
raise RuntimeError("Codex CLI timed out") from exc
@@ -301,7 +291,7 @@ def normalize_job_description(job_file: Path) -> NormalizedJobDescription:
prompt_path.write_text(prompt_text, encoding="utf-8")
output_path = tmp_dir / "normalize_output.md"
run_codex(prompt_path, output_path, CODEX_NORMALIZER_COMMAND_TEMPLATE)
run_codex(prompt_path, output_path)
normalized_text = output_path.read_text(encoding="utf-8").strip()
return parse_normalized_output(normalized_text)
@@ -356,7 +346,7 @@ def process_job(job_file: Path) -> None:
prompt_path.write_text(prompt_text, encoding="utf-8")
output_path = tmp_dir / "codex_output.md"
run_codex(prompt_path, output_path, CODEX_COMMAND_TEMPLATE)
run_codex(prompt_path, output_path)
generated_output = out_dir / output_filename
counter = 1