Files
clawbot/skills/codex-iterm/scripts/run_codex_iterm.py
T
2026-02-19 10:44:21 -05:00

44 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""Helper to run Codex commands inside iTerm so the user can watch output."""
import argparse
import shlex
import subprocess
from pathlib import Path
DEFAULT_CODEX = "/Applications/Codex.app/Contents/Resources/codex"
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("prompt", help="Codex prompt/instruction string")
parser.add_argument("--workdir", default=str(Path.home() / "Project/basic1"),
help="Working directory for the Codex session")
parser.add_argument("--flags", default="--full-auto",
help="Additional flags to pass to Codex (e.g. '--yolo')")
parser.add_argument("--codex-path", default=DEFAULT_CODEX,
help="Path to the Codex CLI binary")
parser.add_argument("--applescript", default=str(Path(__file__).with_name("run_codex_iterm.applescript")),
help="Path to the AppleScript wrapper")
args = parser.parse_args()
workdir = Path(args.workdir).expanduser()
codex_bin = Path(args.codex_path).expanduser()
applescript = Path(args.applescript).expanduser()
if not codex_bin.exists():
raise SystemExit(f"Codex binary not found at {codex_bin}")
if not applescript.exists():
raise SystemExit(f"AppleScript helper not found at {applescript}")
cmd = f"cd {shlex.quote(str(workdir))} && {shlex.quote(str(codex_bin))} {args.flags} {shlex.quote(args.prompt)}"
subprocess.run([
"osascript",
str(applescript),
cmd,
], check=True)
if __name__ == "__main__":
main()