Files
biliup-next/src/biliup_next/infra/adapters/codex_cli.py

45 lines
1.1 KiB
Python

from __future__ import annotations
import subprocess
from pathlib import Path
from biliup_next.core.errors import ModuleError
class CodexCliAdapter:
def run_song_detect(
self,
*,
codex_cmd: str,
work_dir: Path,
prompt: str,
) -> subprocess.CompletedProcess[str]:
cmd = [
codex_cmd,
"exec",
prompt.replace("\n", " "),
"--full-auto",
"--sandbox",
"workspace-write",
"--output-schema",
"./song_schema.json",
"-o",
"songs.json",
"--skip-git-repo-check",
"--json",
]
try:
return subprocess.run(
cmd,
cwd=str(work_dir),
capture_output=True,
text=True,
check=False,
)
except FileNotFoundError as exc:
raise ModuleError(
code="CODEX_NOT_FOUND",
message=f"找不到 codex 命令: {codex_cmd}",
retryable=False,
) from exc