anosys-codex 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- anosys_codex-0.1.0/LICENSE +1 -0
- anosys_codex-0.1.0/PKG-INFO +142 -0
- anosys_codex-0.1.0/README.md +115 -0
- anosys_codex-0.1.0/pyproject.toml +49 -0
- anosys_codex-0.1.0/setup.cfg +4 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/PKG-INFO +142 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/SOURCES.txt +17 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/dependency_links.txt +1 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/entry_points.txt +2 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/requires.txt +2 -0
- anosys_codex-0.1.0/src/anosys_codex.egg-info/top_level.txt +1 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/__init__.py +40 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/cli.py +200 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/encryption.py +182 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/hook_runner.py +607 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/installer.py +287 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/mapper.py +278 -0
- anosys_codex-0.1.0/src/anosys_sdk_codex/py.typed +0 -0
- anosys_codex-0.1.0/tests/test_codex.py +267 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../../../LICENSE
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: anosys-codex
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AnoSys observability hook for OpenAI Codex CLI
|
|
5
|
+
Author-email: AnoSys <support@anosys.ai>
|
|
6
|
+
License: ../../../LICENSE
|
|
7
|
+
Project-URL: Homepage, https://anosys.ai
|
|
8
|
+
Project-URL: Documentation, https://docs.anosys.ai
|
|
9
|
+
Project-URL: Repository, https://github.com/anosys-ai/anosys-sdk
|
|
10
|
+
Keywords: anosys,codex,openai,observability,monitoring,audit,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.25.1
|
|
25
|
+
Requires-Dist: cryptography>=3.4.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# anosys-codex (Python)
|
|
29
|
+
|
|
30
|
+
AnoSys observability and analytics hook for OpenAI Codex CLI.
|
|
31
|
+
|
|
32
|
+
This package automatically captures Codex CLI's telemetry, agent turns, tool calls (`shell`, `apply_patch`, Code Mode custom tools, `web_search`), token usage breakdowns (prompt, completion, cache read/write, reasoning tokens), and estimated API costs, sending them directly to your AnoSys workspace.
|
|
33
|
+
|
|
34
|
+
It integrates seamlessly with Codex CLI's native `notify` hook mechanism.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install anosys-codex
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
After installing the package, run the setup wizard to configure the hook:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
anosys-codex install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The installer will prompt you for:
|
|
51
|
+
1. **AnoSys API Key for logs**: Your ingestion API key from the [AnoSys Console](https://console.anosys.ai/collect/integrationoptions).
|
|
52
|
+
> **Pixel Type Requirement**: This key must belong to a **`CC` (Claude Code / Codex CLI)** pixel. The installer automatically validates the key against `https://console.anosys.ai/api/resolveapikeys` to ensure it resolves to a `/cc/` endpoint. Keys belonging to `T` (OTEL) or Web Traffic (`a`/`g`) pixels are rejected with a warning.
|
|
53
|
+
2. **Content Redaction**: If enabled, sensitive conversation content (prompts, answers, code, tool inputs/outputs) will be redacted and replaced with `[REDACTED]`. Only metadata and token statistics will be tracked.
|
|
54
|
+
3. **Automatic Config Update**: Confirms whether to automatically write `notify = ["anosys-codex", "run"]` to `~/.codex/config.toml` (and creates a `.bak` backup first).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Non-Interactive / Headless Installation
|
|
59
|
+
|
|
60
|
+
For CI/CD pipelines, Docker containers, devcontainer setups, or non-interactive dotfiles:
|
|
61
|
+
|
|
62
|
+
### Using the `-y` / `--yes` flag (Recommended):
|
|
63
|
+
```bash
|
|
64
|
+
anosys-codex install --api-key "your_logs_api_key" -y
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Using environment variables:
|
|
68
|
+
```bash
|
|
69
|
+
export ANOSYS_API_KEY="your_logs_api_key"
|
|
70
|
+
anosys-codex install -y
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Using explicit granular flags:
|
|
74
|
+
```bash
|
|
75
|
+
anosys-codex install \
|
|
76
|
+
--api-key "your_logs_api_key" \
|
|
77
|
+
--auto-update \
|
|
78
|
+
--no-redaction
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> **Important (Codex Security Trust)**:
|
|
82
|
+
> Codex requires explicit user approval for unmanaged external notify hooks. After running `install`, start a Codex CLI session, type `/hooks`, and select `approve` / `trust` for the `anosys-codex run` hook entry.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## CLI Commands
|
|
87
|
+
|
|
88
|
+
The CLI safely manages `~/.codex/config.toml` and creates automatic timestamped backups (`config.toml.<TIMESTAMP>.bak`) before applying any modifications.
|
|
89
|
+
|
|
90
|
+
### `status`
|
|
91
|
+
Check the current installation and registration status of the hook:
|
|
92
|
+
```bash
|
|
93
|
+
anosys-codex status
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `install`
|
|
97
|
+
Installs or updates the notify hook in `~/.codex/config.toml` and creates `~/.codex/anosys-env.sh`:
|
|
98
|
+
```bash
|
|
99
|
+
anosys-codex install [options]
|
|
100
|
+
|
|
101
|
+
Options:
|
|
102
|
+
--api-key <key> AnoSys logs API key
|
|
103
|
+
-y, --yes Skip interactive prompts (non-interactive mode)
|
|
104
|
+
--redaction Enable content redaction
|
|
105
|
+
--no-redaction Disable content redaction
|
|
106
|
+
--auto-update Automatically update ~/.codex/config.toml
|
|
107
|
+
--no-auto-update Print manual setup instructions instead of modifying config
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `uninstall`
|
|
111
|
+
Safely removes the AnoSys notify hook entry from `~/.codex/config.toml` and deletes `~/.codex/anosys-env.sh`:
|
|
112
|
+
```bash
|
|
113
|
+
anosys-codex uninstall
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `run`
|
|
117
|
+
Executed automatically by the Codex CLI on turn-complete notify events. You do not need to invoke this manually:
|
|
118
|
+
```bash
|
|
119
|
+
anosys-codex run
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## How It Works
|
|
125
|
+
|
|
126
|
+
1. When a Codex turn completes, Codex CLI triggers `notify = ["anosys-codex", "run"]` defined in `~/.codex/config.toml`.
|
|
127
|
+
2. The hook runner receives the session thread ID and locates the session's rollout transcript at `~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<session_id>.jsonl`.
|
|
128
|
+
3. It incrementally extracts user prompts, assistant messages, model details, token counts (including cached inputs and reasoning tokens), and tool calls.
|
|
129
|
+
4. It maps the turn into the AnoSys schema (`cvs200: 'CodexHook'`), estimates USD cost using OpenAI's model pricing table, applies optional PII redaction, and batches the payload to `https://api.anosys.ai/ingestion`.
|
|
130
|
+
5. If network connectivity is temporarily unavailable, failed records are buffered locally in `~/.codex/state/pending_records.jsonl` and automatically replayed on subsequent runs.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Environment Variables
|
|
135
|
+
|
|
136
|
+
| Variable | Description |
|
|
137
|
+
|----------|-------------|
|
|
138
|
+
| `ANOSYS_HOOK_APIKEY` / `ANOSYS_API_KEY` | AnoSys ingestion API key |
|
|
139
|
+
| `ANOSYS_HOOK_ENDPOINT_URL` | Override default ingestion URL (`https://api.anosys.ai/ingestion`) |
|
|
140
|
+
| `REDACTION` / `ANOSYS_REDACT_CONTENT` | Set to `"true"` to redact prompts, code, and tool outputs |
|
|
141
|
+
| `ANOSYS_HOOK_DRY_RUN` | Set to `"true"` to log payloads to stderr without sending to network |
|
|
142
|
+
| `CODEX_HOME` | Custom directory for Codex config and sessions (defaults to `~/.codex`) |
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# anosys-codex (Python)
|
|
2
|
+
|
|
3
|
+
AnoSys observability and analytics hook for OpenAI Codex CLI.
|
|
4
|
+
|
|
5
|
+
This package automatically captures Codex CLI's telemetry, agent turns, tool calls (`shell`, `apply_patch`, Code Mode custom tools, `web_search`), token usage breakdowns (prompt, completion, cache read/write, reasoning tokens), and estimated API costs, sending them directly to your AnoSys workspace.
|
|
6
|
+
|
|
7
|
+
It integrates seamlessly with Codex CLI's native `notify` hook mechanism.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install anosys-codex
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
After installing the package, run the setup wizard to configure the hook:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
anosys-codex install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The installer will prompt you for:
|
|
24
|
+
1. **AnoSys API Key for logs**: Your ingestion API key from the [AnoSys Console](https://console.anosys.ai/collect/integrationoptions).
|
|
25
|
+
> **Pixel Type Requirement**: This key must belong to a **`CC` (Claude Code / Codex CLI)** pixel. The installer automatically validates the key against `https://console.anosys.ai/api/resolveapikeys` to ensure it resolves to a `/cc/` endpoint. Keys belonging to `T` (OTEL) or Web Traffic (`a`/`g`) pixels are rejected with a warning.
|
|
26
|
+
2. **Content Redaction**: If enabled, sensitive conversation content (prompts, answers, code, tool inputs/outputs) will be redacted and replaced with `[REDACTED]`. Only metadata and token statistics will be tracked.
|
|
27
|
+
3. **Automatic Config Update**: Confirms whether to automatically write `notify = ["anosys-codex", "run"]` to `~/.codex/config.toml` (and creates a `.bak` backup first).
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Non-Interactive / Headless Installation
|
|
32
|
+
|
|
33
|
+
For CI/CD pipelines, Docker containers, devcontainer setups, or non-interactive dotfiles:
|
|
34
|
+
|
|
35
|
+
### Using the `-y` / `--yes` flag (Recommended):
|
|
36
|
+
```bash
|
|
37
|
+
anosys-codex install --api-key "your_logs_api_key" -y
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Using environment variables:
|
|
41
|
+
```bash
|
|
42
|
+
export ANOSYS_API_KEY="your_logs_api_key"
|
|
43
|
+
anosys-codex install -y
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using explicit granular flags:
|
|
47
|
+
```bash
|
|
48
|
+
anosys-codex install \
|
|
49
|
+
--api-key "your_logs_api_key" \
|
|
50
|
+
--auto-update \
|
|
51
|
+
--no-redaction
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
> **Important (Codex Security Trust)**:
|
|
55
|
+
> Codex requires explicit user approval for unmanaged external notify hooks. After running `install`, start a Codex CLI session, type `/hooks`, and select `approve` / `trust` for the `anosys-codex run` hook entry.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## CLI Commands
|
|
60
|
+
|
|
61
|
+
The CLI safely manages `~/.codex/config.toml` and creates automatic timestamped backups (`config.toml.<TIMESTAMP>.bak`) before applying any modifications.
|
|
62
|
+
|
|
63
|
+
### `status`
|
|
64
|
+
Check the current installation and registration status of the hook:
|
|
65
|
+
```bash
|
|
66
|
+
anosys-codex status
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `install`
|
|
70
|
+
Installs or updates the notify hook in `~/.codex/config.toml` and creates `~/.codex/anosys-env.sh`:
|
|
71
|
+
```bash
|
|
72
|
+
anosys-codex install [options]
|
|
73
|
+
|
|
74
|
+
Options:
|
|
75
|
+
--api-key <key> AnoSys logs API key
|
|
76
|
+
-y, --yes Skip interactive prompts (non-interactive mode)
|
|
77
|
+
--redaction Enable content redaction
|
|
78
|
+
--no-redaction Disable content redaction
|
|
79
|
+
--auto-update Automatically update ~/.codex/config.toml
|
|
80
|
+
--no-auto-update Print manual setup instructions instead of modifying config
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `uninstall`
|
|
84
|
+
Safely removes the AnoSys notify hook entry from `~/.codex/config.toml` and deletes `~/.codex/anosys-env.sh`:
|
|
85
|
+
```bash
|
|
86
|
+
anosys-codex uninstall
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `run`
|
|
90
|
+
Executed automatically by the Codex CLI on turn-complete notify events. You do not need to invoke this manually:
|
|
91
|
+
```bash
|
|
92
|
+
anosys-codex run
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## How It Works
|
|
98
|
+
|
|
99
|
+
1. When a Codex turn completes, Codex CLI triggers `notify = ["anosys-codex", "run"]` defined in `~/.codex/config.toml`.
|
|
100
|
+
2. The hook runner receives the session thread ID and locates the session's rollout transcript at `~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<session_id>.jsonl`.
|
|
101
|
+
3. It incrementally extracts user prompts, assistant messages, model details, token counts (including cached inputs and reasoning tokens), and tool calls.
|
|
102
|
+
4. It maps the turn into the AnoSys schema (`cvs200: 'CodexHook'`), estimates USD cost using OpenAI's model pricing table, applies optional PII redaction, and batches the payload to `https://api.anosys.ai/ingestion`.
|
|
103
|
+
5. If network connectivity is temporarily unavailable, failed records are buffered locally in `~/.codex/state/pending_records.jsonl` and automatically replayed on subsequent runs.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Environment Variables
|
|
108
|
+
|
|
109
|
+
| Variable | Description |
|
|
110
|
+
|----------|-------------|
|
|
111
|
+
| `ANOSYS_HOOK_APIKEY` / `ANOSYS_API_KEY` | AnoSys ingestion API key |
|
|
112
|
+
| `ANOSYS_HOOK_ENDPOINT_URL` | Override default ingestion URL (`https://api.anosys.ai/ingestion`) |
|
|
113
|
+
| `REDACTION` / `ANOSYS_REDACT_CONTENT` | Set to `"true"` to redact prompts, code, and tool outputs |
|
|
114
|
+
| `ANOSYS_HOOK_DRY_RUN` | Set to `"true"` to log payloads to stderr without sending to network |
|
|
115
|
+
| `CODEX_HOME` | Custom directory for Codex config and sessions (defaults to `~/.codex`) |
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "anosys-codex"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "AnoSys observability hook for OpenAI Codex CLI"
|
|
9
|
+
authors = [{name = "AnoSys", email = "support@anosys.ai"}]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = {file = "LICENSE"}
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
"Topic :: System :: Monitoring",
|
|
24
|
+
]
|
|
25
|
+
keywords = ["anosys", "codex", "openai", "observability", "monitoring", "audit", "llm"]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"requests>=2.25.1",
|
|
28
|
+
"cryptography>=3.4.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
anosys-codex = "anosys_sdk_codex.cli:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://anosys.ai"
|
|
36
|
+
Documentation = "https://docs.anosys.ai"
|
|
37
|
+
Repository = "https://github.com/anosys-ai/anosys-sdk"
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
"anosys_sdk_codex" = ["py.typed"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E4", "E7", "E9", "F"]
|
|
47
|
+
|
|
48
|
+
[tool.ruff.lint.per-file-ignores]
|
|
49
|
+
"src/anosys_sdk_codex/mapper.py" = ["E701", "E702"]
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: anosys-codex
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AnoSys observability hook for OpenAI Codex CLI
|
|
5
|
+
Author-email: AnoSys <support@anosys.ai>
|
|
6
|
+
License: ../../../LICENSE
|
|
7
|
+
Project-URL: Homepage, https://anosys.ai
|
|
8
|
+
Project-URL: Documentation, https://docs.anosys.ai
|
|
9
|
+
Project-URL: Repository, https://github.com/anosys-ai/anosys-sdk
|
|
10
|
+
Keywords: anosys,codex,openai,observability,monitoring,audit,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.25.1
|
|
25
|
+
Requires-Dist: cryptography>=3.4.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# anosys-codex (Python)
|
|
29
|
+
|
|
30
|
+
AnoSys observability and analytics hook for OpenAI Codex CLI.
|
|
31
|
+
|
|
32
|
+
This package automatically captures Codex CLI's telemetry, agent turns, tool calls (`shell`, `apply_patch`, Code Mode custom tools, `web_search`), token usage breakdowns (prompt, completion, cache read/write, reasoning tokens), and estimated API costs, sending them directly to your AnoSys workspace.
|
|
33
|
+
|
|
34
|
+
It integrates seamlessly with Codex CLI's native `notify` hook mechanism.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install anosys-codex
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
After installing the package, run the setup wizard to configure the hook:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
anosys-codex install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The installer will prompt you for:
|
|
51
|
+
1. **AnoSys API Key for logs**: Your ingestion API key from the [AnoSys Console](https://console.anosys.ai/collect/integrationoptions).
|
|
52
|
+
> **Pixel Type Requirement**: This key must belong to a **`CC` (Claude Code / Codex CLI)** pixel. The installer automatically validates the key against `https://console.anosys.ai/api/resolveapikeys` to ensure it resolves to a `/cc/` endpoint. Keys belonging to `T` (OTEL) or Web Traffic (`a`/`g`) pixels are rejected with a warning.
|
|
53
|
+
2. **Content Redaction**: If enabled, sensitive conversation content (prompts, answers, code, tool inputs/outputs) will be redacted and replaced with `[REDACTED]`. Only metadata and token statistics will be tracked.
|
|
54
|
+
3. **Automatic Config Update**: Confirms whether to automatically write `notify = ["anosys-codex", "run"]` to `~/.codex/config.toml` (and creates a `.bak` backup first).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Non-Interactive / Headless Installation
|
|
59
|
+
|
|
60
|
+
For CI/CD pipelines, Docker containers, devcontainer setups, or non-interactive dotfiles:
|
|
61
|
+
|
|
62
|
+
### Using the `-y` / `--yes` flag (Recommended):
|
|
63
|
+
```bash
|
|
64
|
+
anosys-codex install --api-key "your_logs_api_key" -y
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Using environment variables:
|
|
68
|
+
```bash
|
|
69
|
+
export ANOSYS_API_KEY="your_logs_api_key"
|
|
70
|
+
anosys-codex install -y
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Using explicit granular flags:
|
|
74
|
+
```bash
|
|
75
|
+
anosys-codex install \
|
|
76
|
+
--api-key "your_logs_api_key" \
|
|
77
|
+
--auto-update \
|
|
78
|
+
--no-redaction
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> **Important (Codex Security Trust)**:
|
|
82
|
+
> Codex requires explicit user approval for unmanaged external notify hooks. After running `install`, start a Codex CLI session, type `/hooks`, and select `approve` / `trust` for the `anosys-codex run` hook entry.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## CLI Commands
|
|
87
|
+
|
|
88
|
+
The CLI safely manages `~/.codex/config.toml` and creates automatic timestamped backups (`config.toml.<TIMESTAMP>.bak`) before applying any modifications.
|
|
89
|
+
|
|
90
|
+
### `status`
|
|
91
|
+
Check the current installation and registration status of the hook:
|
|
92
|
+
```bash
|
|
93
|
+
anosys-codex status
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `install`
|
|
97
|
+
Installs or updates the notify hook in `~/.codex/config.toml` and creates `~/.codex/anosys-env.sh`:
|
|
98
|
+
```bash
|
|
99
|
+
anosys-codex install [options]
|
|
100
|
+
|
|
101
|
+
Options:
|
|
102
|
+
--api-key <key> AnoSys logs API key
|
|
103
|
+
-y, --yes Skip interactive prompts (non-interactive mode)
|
|
104
|
+
--redaction Enable content redaction
|
|
105
|
+
--no-redaction Disable content redaction
|
|
106
|
+
--auto-update Automatically update ~/.codex/config.toml
|
|
107
|
+
--no-auto-update Print manual setup instructions instead of modifying config
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `uninstall`
|
|
111
|
+
Safely removes the AnoSys notify hook entry from `~/.codex/config.toml` and deletes `~/.codex/anosys-env.sh`:
|
|
112
|
+
```bash
|
|
113
|
+
anosys-codex uninstall
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `run`
|
|
117
|
+
Executed automatically by the Codex CLI on turn-complete notify events. You do not need to invoke this manually:
|
|
118
|
+
```bash
|
|
119
|
+
anosys-codex run
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## How It Works
|
|
125
|
+
|
|
126
|
+
1. When a Codex turn completes, Codex CLI triggers `notify = ["anosys-codex", "run"]` defined in `~/.codex/config.toml`.
|
|
127
|
+
2. The hook runner receives the session thread ID and locates the session's rollout transcript at `~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<session_id>.jsonl`.
|
|
128
|
+
3. It incrementally extracts user prompts, assistant messages, model details, token counts (including cached inputs and reasoning tokens), and tool calls.
|
|
129
|
+
4. It maps the turn into the AnoSys schema (`cvs200: 'CodexHook'`), estimates USD cost using OpenAI's model pricing table, applies optional PII redaction, and batches the payload to `https://api.anosys.ai/ingestion`.
|
|
130
|
+
5. If network connectivity is temporarily unavailable, failed records are buffered locally in `~/.codex/state/pending_records.jsonl` and automatically replayed on subsequent runs.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Environment Variables
|
|
135
|
+
|
|
136
|
+
| Variable | Description |
|
|
137
|
+
|----------|-------------|
|
|
138
|
+
| `ANOSYS_HOOK_APIKEY` / `ANOSYS_API_KEY` | AnoSys ingestion API key |
|
|
139
|
+
| `ANOSYS_HOOK_ENDPOINT_URL` | Override default ingestion URL (`https://api.anosys.ai/ingestion`) |
|
|
140
|
+
| `REDACTION` / `ANOSYS_REDACT_CONTENT` | Set to `"true"` to redact prompts, code, and tool outputs |
|
|
141
|
+
| `ANOSYS_HOOK_DRY_RUN` | Set to `"true"` to log payloads to stderr without sending to network |
|
|
142
|
+
| `CODEX_HOME` | Custom directory for Codex config and sessions (defaults to `~/.codex`) |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/anosys_codex.egg-info/PKG-INFO
|
|
5
|
+
src/anosys_codex.egg-info/SOURCES.txt
|
|
6
|
+
src/anosys_codex.egg-info/dependency_links.txt
|
|
7
|
+
src/anosys_codex.egg-info/entry_points.txt
|
|
8
|
+
src/anosys_codex.egg-info/requires.txt
|
|
9
|
+
src/anosys_codex.egg-info/top_level.txt
|
|
10
|
+
src/anosys_sdk_codex/__init__.py
|
|
11
|
+
src/anosys_sdk_codex/cli.py
|
|
12
|
+
src/anosys_sdk_codex/encryption.py
|
|
13
|
+
src/anosys_sdk_codex/hook_runner.py
|
|
14
|
+
src/anosys_sdk_codex/installer.py
|
|
15
|
+
src/anosys_sdk_codex/mapper.py
|
|
16
|
+
src/anosys_sdk_codex/py.typed
|
|
17
|
+
tests/test_codex.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
anosys_sdk_codex
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AnoSys OpenAI Codex CLI integration — observability hook for Codex sessions.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
except ImportError:
|
|
8
|
+
from importlib_metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
from anosys_sdk_codex.installer import update_codex_config, update_codex_env
|
|
11
|
+
from anosys_sdk_codex.mapper import transform_codex_turn
|
|
12
|
+
from anosys_sdk_codex.encryption import (
|
|
13
|
+
ANOSYS_ENCRYPTION_PREFIX,
|
|
14
|
+
DEFAULT_ENCRYPTED_COLUMNS,
|
|
15
|
+
derive_256_bit_key,
|
|
16
|
+
encrypt,
|
|
17
|
+
decrypt,
|
|
18
|
+
get_encryption_key,
|
|
19
|
+
get_target_columns,
|
|
20
|
+
encrypt_payload,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
__version__ = version("anosys-codex")
|
|
25
|
+
except PackageNotFoundError:
|
|
26
|
+
__version__ = "0.1.0"
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"transform_codex_turn",
|
|
30
|
+
"update_codex_config",
|
|
31
|
+
"update_codex_env",
|
|
32
|
+
"ANOSYS_ENCRYPTION_PREFIX",
|
|
33
|
+
"DEFAULT_ENCRYPTED_COLUMNS",
|
|
34
|
+
"derive_256_bit_key",
|
|
35
|
+
"encrypt",
|
|
36
|
+
"decrypt",
|
|
37
|
+
"get_encryption_key",
|
|
38
|
+
"get_target_columns",
|
|
39
|
+
"encrypt_payload",
|
|
40
|
+
]
|