Skip to content

feat: add codex-cli backend to standalone CLI (Issue #69 v1)#70

Merged
devswha merged 1 commit intomainfrom
feat/codex-cli-backend
May 3, 2026
Merged

feat: add codex-cli backend to standalone CLI (Issue #69 v1)#70
devswha merged 1 commit intomainfrom
feat/codex-cli-backend

Conversation

@devswha
Copy link
Copy Markdown
Owner

@devswha devswha commented May 3, 2026

Closes the v1 phase of #69.

Summary

  • New src/backends/ abstraction with two implementations: openai-http (wraps existing api.js, default) and codex-cli (spawns local codex exec --skip-git-repo-check --output-last-message <tmpfile>, pipes prompt via stdin).
  • New CLI flags: --backend <name> (explicit selection) and --list-backends (lists registered backends + availability check).
  • Heuristic in selectBackend: explicit --backend wins → else --model codex* routes to codex-cli → else openai-http.
  • v1 scope: only single-mode rewrites use the backend abstraction. --audit, --score, --diff, --ouroboros, and --models/MAX still go through the HTTP backend (documented in READMEs and the issue phasing).

Verified end-to-end

Real run on a 189-char Korean AI sample (no API key, codex OAuth):

$ patina --backend codex-cli --lang ko /tmp/sample.txt
요즘 커피는 그냥 마시는 걸로 끝나지 않는다. 누군가에겐 출근 전 루틴이고,
누군가에겐 친구를 만나는 핑계다. 카페는 조용히 일하는 사람, 오래 수다 떠는
사람, 잠깐 숨 돌리러 들어온 사람이 뒤섞이는 공간이 됐다.
...

~9s wall, all canonical AI patterns removed (~다는 점, 주목할 만, 의미 있는 교류, 지속될 것으로 전망, 격식체→평어체, 추상→구체).

Test plan

  • npm test — 33 / 33 pass (12 new unit tests in backends.test.js + 21 existing)
  • node bin/patina.js --help shows new flags
  • node bin/patina.js --list-backends shows openai-http available + codex-cli available
  • Real e2e run with --backend codex-cli produces valid humanized output
  • README + KR / JA / ZH translations synced

Out of scope (v2+, tracked in #69)

  • claude-cli, gemini-cli backends
  • Mixed-backend MAX mode
  • patina doctor health check

🤖 Generated with Claude Code

The standalone CLI previously required a PATINA_API_KEY because every
single-mode rewrite went through src/api.js (OpenAI HTTP). This adds a
backend abstraction with two implementations and lets users skip the
API key entirely by running rewrites through the local codex CLI, which
authenticates via OpenAI/ChatGPT OAuth.

Verified end-to-end on a 189-char Korean AI sample (PR #69 background):
codex backend removed the canonical patterns ("~다는 점", "주목할 만",
"의미 있는 교류", "지속될 것으로 전망", 격식체→평어체, 추상→구체) in
~9s with no API key.

Changes:
- src/backends/codex-cli.js — spawn `codex exec --skip-git-repo-check
  --output-last-message <tmpfile>`, pipe prompt via stdin, read result.
  Handles ENOENT (codex not installed), exit code, and timeout.
- src/backends/index.js — registry + selectBackend() with heuristic:
  explicit --backend wins, then --model codex* routes to codex-cli,
  else openai-http (existing behavior).
- src/cli.js — adds --backend and --list-backends flags, routes the
  single-mode rewrite path through selectBackend(). MAX (--models) and
  --ouroboros still go through the HTTP backend in v1; documented.
- tests/e2e/backends.test.js — 12 unit tests for selection heuristic
  and listing. All 33 tests pass.
- README.md / README_KR.md / README_JA.md / README_ZH.md — document
  the new backend, list-backends flag, and v1 scope (single-mode only).

Refs #69.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant