Skip to content

[codex] Improve CLI reliability and tooling#1

Merged
hamakyo merged 2 commits into
mainfrom
codex/improve-cli-reliability-and-tooling
Apr 12, 2026
Merged

[codex] Improve CLI reliability and tooling#1
hamakyo merged 2 commits into
mainfrom
codex/improve-cli-reliability-and-tooling

Conversation

@hamakyo

@hamakyo hamakyo commented Apr 11, 2026

Copy link
Copy Markdown
Owner

What changed

  • rebuilt the CLI discussion runner so provider methods are correctly scoped and the app no longer fails at runtime
  • added configurable provider selection, output formats, output files, quiet mode, timeouts, and retry controls
  • added repository hygiene and tooling files: .gitignore, .env.example, README.md, CI, ruff, mypy, and unit tests
  • removed tracked .env from the repository so local secrets stay out of Git

Why it changed

The repository had a broken class structure, no test coverage, weak dependency management, and tracked local secrets. The CLI was also hard to automate because it lacked structured output and runtime controls.

Impact

The project is now runnable, testable, safer to share, and easier to use from scripts or CI.

Root cause

Core methods had drifted out of the class body, secret handling relied on a tracked .env, and there was no automation to catch regressions.

Validation

  • python -m unittest discover -s tests -v
  • .venv/bin/ruff check .
  • .venv/bin/mypy
  • python -m py_compile mogisystem.py tests/test_mogisystem.py

Summary by CodeRabbit

リリースノート

  • New Features

    • CLIプロバイダ選択(--providers)、複数出力形式(JSON/Markdown)、静寂モード、タイムアウト/リトライ制御を追加
    • 条件付きプロバイダ初期化により効率化
  • Tests

    • エンドツーエンド機能、エラー処理、タイムアウト、リトライ動作を検証する包括的なテストスイート追加
  • Documentation

    • セットアップ、使用方法、設定オプション、セキュリティのベストプラクティスを含むREADME追加
  • Chores

    • CI/CDパイプライン、環境変数設定、依存関係のバージョン固定、Python品質チェックツール設定を追加

@coderabbitai

coderabbitai Bot commented Apr 11, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

環境設定をリポジトリから削除し、スキーマとして .env.example ファイルを追加しました。また、複数プロバイダー対応、CLIオプション拡張、タイムアウト・リトライ機能、複数出力形式、CI/CDワークフロー、テストスイート、および包括的なドキュメントを導入し、プロジェクトの堅牢性と機能性を向上させました。

Changes

Cohort / File(s) Summary
環境設定管理
.env, .env.example
.env ファイルを削除し、プレースホルダー値を含む .env.example に置き換えました。OpenAI、Anthropic、Google/Gemini の API キーとモデル指定用の環境変数テンプレートを提供します。
プロジェクト設定ファイル
.gitignore, pyproject.toml
.gitignore に Python 関連のキャッシュディレクトリと .env ファイルを追加しました。pyproject.toml に Ruff(100字制限、ルール E/F/I/B)と MyPy(Python 3.11 対応、厳密な型チェック)の設定を追加しました。
依存関係管理
requirements.txt, requirements-dev.txt
requirements.txt で OpenAI(1.55.0)、Anthropic(0.39.0)、google-generativeai(0.8.3)、python-dotenv(0.21.0)をピン止めし、grpcio を削除しました。requirements-dev.txt に mypy(>=1.11, <2)と ruff(>=0.6, <1)を追加しました。
CI/CDワークフロー
.github/workflows/ci.yml
新規 CI ワークフローを追加しました。Ubuntu 上で Python 3.11 を使用し、ruff(リント)、mypy(型チェック)、py_compile(構文検証)、unittest(ユニットテスト実行)を実行します。
ドキュメント
README.md
新規 README(日本語)を追加しました。環境セットアップ、API キー設定、インタラクティブ/引数ベース実行、プロバイダー選択、出力形式(テキスト/JSON/Markdown)、タイムアウト・リトライ設定、セキュリティに関する注意事項を記載しました。
メインシステム
mogisystem.py
プロバイダー選択機能(--providers)、CLI 拡張(--output--output-file--quiet--sleep-seconds--timeout-seconds--retry-count)、条件付きプロバイダー初期化、タイムアウト実装(バックグラウンドスレッド)、リトライロジック、ラウンドベースディスカッション(進捗表示オプション)、複数出力形式(JSON/Markdown)、ファイル書き込み機能を追加しました。
テストスイート
tests/test_mogisystem.py
新規テストスイート(380行)を追加しました。フルディスカッションフロー、プロバイダー欠落時の動作、ラウンド検証、引数パース、タイムアウト・リトライ動作、CLI 出力モード(JSON/Markdown)、ファイル出力機能をカバーする包括的なテストケースを含みます。

Sequence Diagram(s)

sequenceDiagram
    actor User as ユーザー
    participant CLI as CLI<br/>(main)
    participant System as MAGISystem
    participant PM as Provider<br/>Manager
    participant P as Providers<br/>(OpenAI,<br/>Anthropic,<br/>Google)
    participant Handler as Response<br/>Handler
    participant Output as Output<br/>Formatter

    User->>CLI: トピック、ラウンド数、プロバイダー指定
    CLI->>System: 初期化(プロバイダー選択)
    System->>PM: 要求されたプロバイダーのみ初期化
    PM->>P: クライアント初期化
    P-->>PM: クライアント/エラー状態
    PM-->>System: available_models、client_errors
    
    loop 各ラウンド
        CLI->>System: facilitate_discussion()
        System->>System: プロンプト準備
        
        loop 要求されたプロバイダーごと
            System->>Handler: _get_model_handler()
            Handler->>System: get_ai_response()
            System->>System: _run_with_timeout()
            
            par タイムアウトチェック
                System->>P: API呼び出し(バックグラウンドスレッド)
                P-->>System: レスポンス
            and タイムアウト監視
                System->>System: timeout_seconds 監視
            end
            
            System->>System: リトライロジック(retry_count)
            System-->>Handler: AIResponse(content/error)
            Handler-->>System: ハンドル済みレスポンス
        end
        
        System->>System: discussion_history 更新
    end
    
    System->>System: _select_conclusion_model()
    System->>System: 結論生成(利用可能プロバイダー)
    System-->>Output: discussion_history、結論
    
    Output->>Output: 出力形式選択(text/JSON/Markdown)
    Output->>Output: render_result() / render_markdown()
    Output-->>CLI: フォーマット済み結果
    
    CLI->>CLI: _emit_output() / write_output()
    alt ファイル出力
        CLI->>CLI: ディレクトリ作成(必要に応じて)
        CLI->>Output: ファイルに書き込み
    else stdout
        CLI-->>User: 結果表示
    end
Loading
sequenceDiagram
    actor User as ユーザー
    participant CLI as CLI
    participant System as MAGISystem
    participant Provider as Provider<br/>(タイムアウト/リトライ対象)

    User->>CLI: --timeout-seconds 60、--retry-count 2 を指定
    CLI->>System: facilitate_discussion()
    
    loop 各ラウンド、各プロバイダー
        System->>System: _run_with_timeout() 呼び出し
        
        activate System
        par API呼び出し(バックグラウンドスレッド)
            System->>Provider: get_ai_response()
            Note over Provider: 処理中(timeout_seconds 経過)
            Provider-->>System: timeout に達する前に完了 または タイムアウト
        and タイムアウト監視(メインスレッド)
            System->>System: timeout_seconds の経過を監視
            alt timeout 発生
                System-->>System: AIResponse(error="timeout")
            else 正常完了
                System-->>System: AIResponse(content=...)
            end
        end
        deactivate System
        
        System->>System: retry_count でリトライロジック実行
        
        alt エラーあり かつ リトライ可能
            System->>Provider: get_ai_response()(リトライ)
            Provider-->>System: AIResponse
        end
    end
    
    System-->>CLI: 最終結果(content/error)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 ✨ プロバイダー三つの声が合わさり、
タイムアウトとリトライで堅牢に、
CLIは賢く、出力は自由自在、
テストに守られ、ワークフロー回り、
この変化こそ、プロジェクトの羽ばたき! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルはCLIの信頼性とツーリングの改善という主要な変更内容を明確に要約しており、変更セット全体を適切に反映しています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/improve-cli-reliability-and-tooling

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hamakyo hamakyo marked this pull request as ready for review April 12, 2026 12:39
@hamakyo hamakyo merged commit 3042d0d into main Apr 12, 2026
2 of 3 checks passed
@hamakyo hamakyo deleted the codex/improve-cli-reliability-and-tooling branch April 12, 2026 12:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6155b5c66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread mogisystem.py
Comment on lines +208 to +210
worker.join(self.timeout_seconds)

if worker.is_alive():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cancel timed-out provider calls before retrying

When a provider exceeds timeout_seconds, the code returns a timeout error immediately but leaves the worker thread running in the background. If retry_count > 0, the next attempt starts a second API call while the first is still in flight, which can produce duplicate billed requests and extra rate-limit pressure under slow upstream responses. This affects any run where providers are slow/intermittent and makes timeout+retry behavior unsafe for production usage.

Useful? React with 👍 / 👎.

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