Advanced automation framework for Codex AI with comprehensive health monitoring, multi-provider support, and powerful log parsing capabilities
Project description
Codex Interaction Library
A comprehensive Python library for interacting with Codex, parsing logs, and managing Codex runs. Each run of Codex is represented as its own class with parsing capabilities for outputs.
Features
- Individual Codex Runs: Each Codex execution is represented as a
CodexRunclass with complete lifecycle management - Session Management: Group multiple runs into sessions with
CodexSessionfor batch processing - Log Parsing: Comprehensive parsing of Codex log files with multiple extraction types
- Template Processing: Jinja2-based template processing for dynamic prompt generation
- CSV Integration: Built-in support for processing CSV data with templated prompts
- File Management: Utilities for backups, file operations, and directory management
- Diff Utilities: Tools for analyzing and displaying file changes
- Pure Interaction Focus: Separated from interface code, focused purely on Codex interaction
Installation
# Install dependencies
pip install jinja2
# The library is designed to be used as a local module
# Copy the codex_interaction directory to your project
Quick Start
Basic Usage
from codex_interaction import CodexRun, CodexSession, CodexLogParser
# Create and execute a single Codex run
run = CodexRun(
prompt="Create a Python function to calculate fibonacci numbers",
model="gpt-4.1-nano",
timeout=300
)
result = run.execute(log_dir="./logs")
print(f"Success: {result.success}")
print(f"Files modified: {result.files_modified}")
Session with Multiple Runs
# Create a session for multiple runs
session = CodexSession(
session_id="my_session",
default_model="gpt-4.1-nano",
log_dir="./logs"
)
# Add multiple runs
session.add_run("Create a calculator class")
session.add_run("Write unit tests for the calculator")
session.add_run("Add documentation to the code")
# Execute all runs
session_result = session.execute_all()
summary = session.get_summary()
CSV Data Processing
from codex_interaction import TemplateProcessor
# CSV data
csv_data = [
{"file_path": "api/users.py", "method": "GET", "endpoint": "/api/users"},
{"file_path": "api/orders.py", "method": "POST", "endpoint": "/api/orders"}
]
# Template
template = """
Analyze the API endpoint {{ endpoint }} with method {{ method }} in {{ file_path }}.
Check for security and error handling.
"""
# Process with session
session = CodexSession()
processor = TemplateProcessor()
result = session.process_csv_data(csv_data, template, processor)
Log Parsing
# Parse existing Codex logs
parser = CodexLogParser(log_dir=".", log_pattern="codex_run_*.log")
# Parse all logs
results = parser.parse_logs()
# Parse specific run
run_result = parser.parse_run("codex_run_20241201_123456.log")
print(f"Changes: {len(run_result.changes)}")
print(f"Tool usage: {len(run_result.tool_usage)}")
Library Architecture
Core Classes
CodexRun: Represents a single Codex execution with full lifecycle managementCodexSession: Manages multiple Codex runs with batch processing capabilitiesCodexRunResult: Contains complete results from a single runCodexSessionResult: Aggregates results from multiple runs
Parsers
CodexLogParser: Main parser for Codex log files with multiple extraction modesCodexOutputParser: Specialized parser for individual command outputs and responses
Extractors
PatchExtractor: Extracts patch/diff information from logsCommandExtractor: Extracts command execution dataToolUsageExtractor: Extracts tool usage informationChangeDetector: Detects various types of changesCustomExtractor: Create custom extraction patterns
Data Models
CodexChange: Represents detected changesPatchData: Represents patch/diff informationCodexCommand: Represents executed commandsToolUsage: Represents tool usage data
Utilities
TemplateProcessor: Jinja2 template processing for promptsFileManager: File operations, backups, CSV handlingDiffUtils: Diff creation and analysis utilitiesColorUtils: Terminal color formatting
Advanced Usage
Custom Extractors
from codex_interaction.extractors import CustomExtractor
# Create custom extractor
custom_extractor = CustomExtractor(
pattern=r'ERROR:\s*(.+)',
change_type="error"
)
# Use with parser
parser = CodexLogParser()
results = parser.parse_logs(extractors=[custom_extractor])
File Filtering
# Filter by file extension
results = parser.parse_logs()
csv_results = parser.filter_by_file_extension(results, '.csv')
# Filter by change type
patch_results = parser.filter_by_change_type(results, 'patch')
Template Variables
from codex_interaction.utils import TemplateProcessor
processor = TemplateProcessor()
# Convert CSV headers to Jinja variables
headers = ["File Path", "HTTP Method", "Priority Level"]
jinja_vars = processor.convert_csv_headers_to_jinja_vars(headers)
# Result: {"FILE_PATH": 0, "HTTP_METHOD": 1, "PRIORITY_LEVEL": 2}
Design Philosophy
This library is designed with separation of concerns in mind:
- Pure Codex Interaction: No UI or interface code, purely focused on Codex operations
- Reusable Components: Each component can be used independently
- Comprehensive Parsing: Extract all meaningful data from Codex operations
- Session Management: Support both single runs and batch operations
- Extensible Architecture: Easy to add new extractors and processors
Use Cases
- Automated Code Analysis: Process multiple files/endpoints systematically
- Log Analysis: Analyze historical Codex operations and results
- Batch Processing: Execute multiple related Codex tasks in sequence
- Template-driven Operations: Use templates to generate consistent prompts
- Integration Projects: Embed Codex interaction into larger systems
Dependencies
jinja2: Template processing- Standard library modules:
os,re,json,csv,subprocess,tempfile, etc.
License
This library is designed for use with other Codex-related projects and can be freely adapted for your needs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file auto_codex-0.1.0.tar.gz.
File metadata
- Download URL: auto_codex-0.1.0.tar.gz
- Upload date:
- Size: 95.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dcb875f16c911c9a298c1dd3c276c05bec3ddb989833aea01bbb39183c268d8
|
|
| MD5 |
b1f5ee233787e1596117fd1590e253bd
|
|
| BLAKE2b-256 |
de1b22439f2ae99d42d3f2ec02d5c775ade0805d456b90d5d756c3b9b97aca80
|
File details
Details for the file auto_codex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: auto_codex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 60.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36ba75482c7028d0589ac690782ef3b51603a1e75e307fde1d22e4967d60934c
|
|
| MD5 |
134d0886cb8eb6fbf7ec274f29e3891e
|
|
| BLAKE2b-256 |
cc856cfe05dc87eb783e076234649c4e4b78d46573d2dde9d1d09655bd0d3c1e
|