Metadata-Version: 2.4
Name: infinium-codex-connector
Version: 1.0.0
Summary: Bridge between Codex CLI hooks and Infinium agent tracing
Project-URL: Homepage, https://github.com/xyendigital/infinium-codex-connector
Project-URL: Repository, https://github.com/xyendigital/infinium-codex-connector
Project-URL: Documentation, https://i42m.ai/docs/codex/index
Project-URL: Bug Tracker, https://github.com/xyendigital/infinium-codex-connector/issues
Author-email: Infinium <support@i42m.ai>
License: MIT License
        
        Copyright (c) 2026 Infinium
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agent,codex,hooks,infinium,observability,openai,tracing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: click>=8.0.0
Requires-Dist: infinium-o2>=1.0.0
Requires-Dist: keyring>=24.0.0
Provides-Extra: dev
Requires-Dist: black>=23.7.0; extra == 'dev'
Requires-Dist: isort>=5.12.0; extra == 'dev'
Requires-Dist: mypy>=1.5.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.11.0; extra == 'dev'
Requires-Dist: pytest>=7.4.0; extra == 'dev'
Provides-Extra: server
Requires-Dist: starlette>=0.27.0; extra == 'server'
Requires-Dist: uvicorn[standard]>=0.23.0; extra == 'server'
Description-Content-Type: text/markdown

# Infinium Codex Connector

Bridge between [Codex CLI](https://developers.openai.com/codex/cli) hooks and [Infinium](https://i42m.ai) agent tracing. Automatically captures Codex CLI sessions — tool calls, prompts, token usage — and sends structured traces to the Infinium platform for Maestro analysis.

## Quick Start

Navigate to your project, install, and set up:

```bash
cd /path/to/your/project
pip install infinium-codex-connector
infinium-codex init
infinium-codex test       # verify credentials + network
```

That's it. Now just use Codex CLI as you normally would — every session is automatically traced to Infinium.

> If `infinium-codex` is not on your PATH, use `python -m infinium_codex_connector` as a drop-in replacement.

## Requirements

- Python 3.9+
- Codex CLI with hooks enabled (`codex features enable codex_hooks`)
- An Infinium agent ID and secret

> **Windows**: requires Codex CLI **v0.119.0 or newer** — earlier versions had hooks gated off on Windows ([openai/codex#17268](https://github.com/openai/codex/pull/17268), merged 2026-04-09).

## How It Works

After `infinium-codex init`, everything is automatic. You use Codex CLI exactly as before — the connector works silently in the background via hooks.

```
Codex CLI ──command hook──> python -m infinium_codex_connector.hook
                                 │
                                 ├─ append event to session JSONL file
                                 │
                                 └─ on Stop:
                                      spawn detached background worker
                                      → replay events → aggregate → send trace
                                                                       │
                                                                       ▼
                                                               Infinium API
                                                           POST /agents/{id}/trace
```

1. Codex CLI fires a command hook for each event (tool call, prompt, etc.)
2. The hook script appends the event to a session JSONL file on disk — returns instantly so Codex is never blocked.
3. On turn completion (`Stop`), a detached background worker replays all events, aggregates them into a structured trace, and sends it to Infinium via the Python SDK.
4. Maestro interprets the trace (grading accuracy, efficiency, prompt adherence).

## CLI Reference

### `infinium-codex init`

Interactive setup wizard. Configures credentials and Codex hooks.

```
Options:
  --agent-id TEXT        Agent ID (skip prompt)
  --agent-secret TEXT    Agent Secret (skip prompt)
  --base-url TEXT        API base URL
  --no-interactive       Use flags only, no prompts (for CI/scripting)
```

### `infinium-codex test`

Send a minimal test trace to verify credentials + network.

```
Options:
  -v, --verbose    Show the full trace payload before sending
```

### `infinium-codex status`

Show current configuration: tracing state, credentials, config source, hook locations, pending retries.

### `infinium-codex pause` / `infinium-codex resume`

Temporarily stop or restart tracing. Hooks stay installed — events are silently skipped while paused.

### `infinium-codex history`

View recently sent traces.

```
Options:
  -n, --limit N    Number of entries (default: 10)
  --json           Output raw JSON lines
  --clear          Delete all history
```

### `infinium-codex errors`

View the connector error log (network failures, bad payloads, keyring issues).

### `infinium-codex retry`

Resend traces that failed due to network issues.

```
Options:
  --dry-run    Show what would be retried without sending
```

### `infinium-codex update-credentials`

Update your Agent ID or Secret.

### `infinium-codex uninstall`

Remove the connector completely — hooks, config file, and keyring secret.

```
Options:
  -y, --yes    Skip confirmation prompt
```

### `infinium-codex cleanup`

Remove stale session files (housekeeping).

### `infinium-codex start`

Start HTTP server mode (alternative to command hooks, requires `pip install infinium-codex-connector[server]`).

## Per-Project Configuration

Each project traces to its own Infinium agent:

```bash
cd /path/to/project-a
infinium-codex init    # Agent A credentials

cd /path/to/project-b
infinium-codex init    # Agent B credentials
```

Config resolution order:
1. **Project config** (`.infinium/config.json` at or above the working directory)
2. **Environment variables** (`INFINIUM_AGENT_ID`, `INFINIUM_AGENT_SECRET` — override for CI/Docker)

Add `.infinium/` to your `.gitignore`.

## Credential Storage

- **Agent ID** and **API URL** are stored in the project config file (`.infinium/config.json`)
- **Agent Secret** is stored in your **OS keyring**:
  - Windows: Credential Manager
  - macOS: Keychain
  - Linux: Secret Service (GNOME Keyring / KWallet)
- Environment variables (`INFINIUM_AGENT_ID`, `INFINIUM_AGENT_SECRET`) override stored values — useful for CI/Docker

## What Gets Traced

| Field | Source |
|-------|--------|
| **name** | First user prompt, truncated (e.g. "Fix the login validation") |
| **description** | First user prompt (full) |
| **duration** | Total session duration in seconds |
| **steps** | Ordered list: user prompts, tool calls |
| **errors** | Tool failures (Codex `tool_response: false`) |
| **environment** | Model, session source, working directory, permission mode |
| **llm_usage** | Prompt / completion / cached input tokens (from Codex transcript) |

### Captured Events

| Event | What It Captures |
|-------|-----------------|
| `SessionStart` | Model, source (startup/resume), working directory |
| `UserPromptSubmit` | User prompt text (truncated) |
| `PreToolUse` / `PostToolUse` | Tool name (Bash), command, success/failure |
| `Stop` | Assistant's final response — triggers trace flush |

## Configuration

Environment variables (all optional — `init` handles the common case):

```bash
# Credentials (override config file + keyring)
INFINIUM_AGENT_ID=...
INFINIUM_AGENT_SECRET=...
INFINIUM_BASE_URL=...

# Connector behavior
CONNECTOR_QUIET=false              # Suppress output
CONNECTOR_FLUSH_ON_STOP=true       # Send trace after each turn
CONNECTOR_FLUSH_ON_SESSION_END=true
CONNECTOR_SESSION_TTL=600          # Stale session cleanup threshold (seconds)
CONNECTOR_SESSION_DIR=...          # Override temp directory for session files
```

## Documentation

Full documentation: [i42m.ai/docs/codex](https://i42m.ai/docs/codex/index)

## License

MIT
