timeplus-agentguard-codex-plugin 0.1.1__tar.gz → 0.3.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.
- timeplus_agentguard_codex_plugin-0.3.0/PKG-INFO +384 -0
- timeplus_agentguard_codex_plugin-0.3.0/README.md +363 -0
- {timeplus_agentguard_codex_plugin-0.1.1 → timeplus_agentguard_codex_plugin-0.3.0}/agentguard_codex/__init__.py +1 -1
- timeplus_agentguard_codex_plugin-0.3.0/agentguard_codex/cli.py +189 -0
- timeplus_agentguard_codex_plugin-0.3.0/agentguard_codex/events.py +428 -0
- timeplus_agentguard_codex_plugin-0.3.0/agentguard_codex/hookevents.py +218 -0
- timeplus_agentguard_codex_plugin-0.3.0/agentguard_codex/sink.py +112 -0
- timeplus_agentguard_codex_plugin-0.3.0/hooks.json +47 -0
- {timeplus_agentguard_codex_plugin-0.1.1 → timeplus_agentguard_codex_plugin-0.3.0}/pyproject.toml +1 -1
- timeplus_agentguard_codex_plugin-0.3.0/tests/test_cli.py +464 -0
- timeplus_agentguard_codex_plugin-0.3.0/tests/test_events.py +719 -0
- timeplus_agentguard_codex_plugin-0.3.0/tests/test_hookevents.py +360 -0
- timeplus_agentguard_codex_plugin-0.3.0/tests/test_sink.py +156 -0
- timeplus_agentguard_codex_plugin-0.1.1/PKG-INFO +0 -154
- timeplus_agentguard_codex_plugin-0.1.1/README.md +0 -133
- timeplus_agentguard_codex_plugin-0.1.1/agentguard_codex/cli.py +0 -125
- timeplus_agentguard_codex_plugin-0.1.1/agentguard_codex/events.py +0 -115
- timeplus_agentguard_codex_plugin-0.1.1/hooks.json +0 -20
- timeplus_agentguard_codex_plugin-0.1.1/tests/test_cli.py +0 -119
- timeplus_agentguard_codex_plugin-0.1.1/tests/test_events.py +0 -188
- {timeplus_agentguard_codex_plugin-0.1.1 → timeplus_agentguard_codex_plugin-0.3.0}/.gitignore +0 -0
- {timeplus_agentguard_codex_plugin-0.1.1 → timeplus_agentguard_codex_plugin-0.3.0}/Makefile +0 -0
- {timeplus_agentguard_codex_plugin-0.1.1 → timeplus_agentguard_codex_plugin-0.3.0}/agentguard_codex/__main__.py +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: timeplus-agentguard-codex-plugin
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: AgentGuard monitoring plugin for OpenAI Codex
|
|
5
|
+
Project-URL: Homepage, https://github.com/timeplus-io/agentguard
|
|
6
|
+
Project-URL: Repository, https://github.com/timeplus-io/agentguard
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Keywords: agentguard,ai-agent,codex,monitoring,observability,security
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Security
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: timeplus-agentguard>=0.3.0
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# agentguard-codex
|
|
23
|
+
|
|
24
|
+
AgentGuard monitoring plugin for [OpenAI Codex](https://github.com/openai/codex).
|
|
25
|
+
|
|
26
|
+
Codex runs a command hook for each lifecycle event and writes one JSON object
|
|
27
|
+
to stdin. This plugin reads that event and sends it to the
|
|
28
|
+
[AgentGuard Timeplus app](https://github.com/timeplus-io/apps/tree/main/apps/agentguard)
|
|
29
|
+
on one of two export paths:
|
|
30
|
+
|
|
31
|
+
| Export | What is sent | Where | Needs |
|
|
32
|
+
|---|---|---|---|
|
|
33
|
+
| `otel` (default) | One OpenTelemetry span per hook, through the [AgentGuard Python SDK](../../../sdk/python) | The app's OTLP/HTTP input (default `http://localhost:4318`) | Port 4318 |
|
|
34
|
+
| `hooks` | One row per hook in the `agentguard_hook_events` stream, like the Claude Code, OpenClaw and Hermes plugins | Timeplus ingest (default `http://localhost:3218`) | Port 3218, or port 8000 with the Timeplus REST API |
|
|
35
|
+
|
|
36
|
+
Exactly one path is active. There is no setting that sends a session on both,
|
|
37
|
+
so the app never sees the same session twice. See
|
|
38
|
+
[Hook-event export](#hook-event-export) for the second path.
|
|
39
|
+
|
|
40
|
+
## Requirements
|
|
41
|
+
|
|
42
|
+
- Python 3.10+
|
|
43
|
+
- A Codex build with hooks enabled
|
|
44
|
+
- The AgentGuard Python SDK ([`timeplus-agentguard`](https://pypi.org/project/timeplus-agentguard/) on PyPI, installed automatically as a dependency). Only the `otel` export uses it; the `hooks` export uses the standard library alone.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install timeplus-agentguard-codex-plugin
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To work on the plugin itself, install it from a checkout instead:
|
|
53
|
+
`pip install -e agents/codex/agentguard-plugin`.
|
|
54
|
+
|
|
55
|
+
## Configure Codex hooks
|
|
56
|
+
|
|
57
|
+
Merge [`hooks.json`](hooks.json) into your Codex hook configuration —
|
|
58
|
+
`~/.codex/hooks.json`, or the equivalent `[hooks]` table in
|
|
59
|
+
`~/.codex/config.toml`:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"hooks": {
|
|
64
|
+
"SessionStart": [
|
|
65
|
+
{ "hooks": [ { "type": "command", "command": "agentguard-codex", "timeout": 10 } ] }
|
|
66
|
+
],
|
|
67
|
+
"Stop": [
|
|
68
|
+
{ "hooks": [ { "type": "command", "command": "agentguard-codex", "timeout": 10 } ] }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The sample registers all 14 Codex lifecycle events with the same command.
|
|
75
|
+
Codex limits `SessionEnd` and `Interrupt` hooks to 3 seconds, so the sample
|
|
76
|
+
gives those two a `timeout` of 3 and the rest 10.
|
|
77
|
+
|
|
78
|
+
Codex skips a new or changed user-level hook until you review it. Run `/hooks`
|
|
79
|
+
in Codex once and approve the AgentGuard entries. Managed (system/MDM) hooks are
|
|
80
|
+
trusted by policy and skip this step.
|
|
81
|
+
|
|
82
|
+
If the plugin is not installed as a console script, use
|
|
83
|
+
`python -m agentguard_codex` as the command instead.
|
|
84
|
+
|
|
85
|
+
### Upgrading from the five-hook configuration
|
|
86
|
+
|
|
87
|
+
Versions before 0.2.0 handled five events: `SessionStart`, `SessionEnd`,
|
|
88
|
+
`UserPromptSubmit`, `PreToolUse` and `PostToolUse`. To capture the other nine:
|
|
89
|
+
|
|
90
|
+
1. Upgrade the package: `pip install -U timeplus-agentguard-codex-plugin`
|
|
91
|
+
(or `pipx upgrade timeplus-agentguard-codex-plugin`). Check with
|
|
92
|
+
`pip show timeplus-agentguard-codex-plugin` that the version is 0.2.0 or later.
|
|
93
|
+
Registering the new events against an older version does nothing: it
|
|
94
|
+
ignores events it does not know.
|
|
95
|
+
2. Add the nine new events to your hook configuration — `PreModelRequest`,
|
|
96
|
+
`PostModelRequest`, `Stop`, `Interrupt`, `SubagentStart`, `SubagentStop`,
|
|
97
|
+
`PermissionRequest`, `PreCompact`, `PostCompact` — copying the entries from
|
|
98
|
+
[`hooks.json`](hooks.json). Use the same `command` as your existing five
|
|
99
|
+
entries (including any absolute path, flags or `env` prefix you added), and
|
|
100
|
+
leave the existing entries in place.
|
|
101
|
+
3. Set `"timeout": 3` on `Interrupt`, and lower `SessionEnd` to 3 if yours
|
|
102
|
+
still says 10.
|
|
103
|
+
4. Start Codex, run `/hooks`, and approve the new and changed entries. Codex
|
|
104
|
+
skips them until you do; the five existing hooks keep running meanwhile.
|
|
105
|
+
|
|
106
|
+
The spans of the five existing events change in 0.2.0 too (see
|
|
107
|
+
[What gets captured](#what-gets-captured)): the agent type is now `codex`
|
|
108
|
+
instead of `agentguard-sdk`, the prompt is a `user_prompt_submit` span instead
|
|
109
|
+
of an `llm` span, and a `session_start` span is sent when the session starts.
|
|
110
|
+
Queries that filter on `service_name = 'agentguard-sdk'` or `span_name = 'llm'`
|
|
111
|
+
need updating.
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
Hooks run in a fresh process, so environment variables are the usual way to
|
|
116
|
+
configure the plugin.
|
|
117
|
+
|
|
118
|
+
| Flag | Environment variable | Default |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `--agent-id` | `AGENTGUARD_AGENT_ID` | hostname |
|
|
121
|
+
| `--deployment-id` | `AGENTGUARD_DEPLOYMENT_ID` | `local` |
|
|
122
|
+
| `--deployment-name` | `AGENTGUARD_DEPLOYMENT_NAME` | `Local Dev` |
|
|
123
|
+
| `--export` | `AGENTGUARD_CODEX_EXPORT` | `otel` |
|
|
124
|
+
| `--endpoint` | `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4318` |
|
|
125
|
+
|
|
126
|
+
`--export` is `otel` or `hooks`. Any other value (including `both`) is
|
|
127
|
+
reported on stderr and treated as `otel`. `--endpoint` applies to the `otel`
|
|
128
|
+
export only; the `hooks` export has its own settings, listed under
|
|
129
|
+
[Hook-event export](#hook-event-export).
|
|
130
|
+
|
|
131
|
+
Flags take precedence over environment variables. The plugin resolves every
|
|
132
|
+
setting (flag, then environment variable, then the default above) before
|
|
133
|
+
constructing the SDK hooks, so each short-lived hook process sees the same
|
|
134
|
+
values — including the agent id, which keys the on-disk Pre/Post-tool timing
|
|
135
|
+
store to match the spans. For example:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
export AGENTGUARD_DEPLOYMENT_ID=production
|
|
139
|
+
export AGENTGUARD_DEPLOYMENT_NAME="Production Codex"
|
|
140
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://timeplus.example.com:4318
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Hook-event export
|
|
144
|
+
|
|
145
|
+
Use this path when the app's OTLP input (port 4318) is not reachable from the
|
|
146
|
+
agent host, or when you want Codex in the same stream as the other plugins.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
export AGENTGUARD_CODEX_EXPORT=hooks
|
|
150
|
+
export AGENTGUARD_TIMEPLUS_URL=http://timeplus.example.com:3218
|
|
151
|
+
export AGENTGUARD_USERNAME=<timeplus-user>
|
|
152
|
+
export AGENTGUARD_PASSWORD=<timeplus-password>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Environment variable | Default | Purpose |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| `AGENTGUARD_TIMEPLUS_URL` | `http://localhost:3218` | Timeplus base URL |
|
|
158
|
+
| `AGENTGUARD_INGEST_API` | `timeplusd` | `timeplusd` (port 3218) or `rest` (the Timeplus REST API, port 8000) |
|
|
159
|
+
| `AGENTGUARD_WORKSPACE` | `default` | REST API workspace id; `default` is correct for self-hosted |
|
|
160
|
+
| `AGENTGUARD_DATABASE` | `ag` | Database of the AgentGuard app |
|
|
161
|
+
| `AGENTGUARD_STREAM` | `agentguard_hook_events` | Target stream |
|
|
162
|
+
| `AGENTGUARD_USERNAME` | `proton` | Timeplus username (Basic auth) |
|
|
163
|
+
| `AGENTGUARD_PASSWORD` | _(empty)_ | Timeplus password (Basic auth) |
|
|
164
|
+
|
|
165
|
+
These are the settings the other hook-event plugins use, with the same
|
|
166
|
+
meaning. They have no flags.
|
|
167
|
+
|
|
168
|
+
Each of the 14 hooks becomes one row:
|
|
169
|
+
|
|
170
|
+
| Column | Value |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `hook_name` | The hook in snake case: `session_start`, `session_end`, `user_prompt_submit`, `pre_tool_use`, `post_tool_use`, `pre_model_request`, `post_model_request`, `stop`, `interrupt`, `subagent_start`, `permission_request`, `pre_compact`, `post_compact`. `SubagentStop` is written as `subagent_ended`, the name the stream already uses for it. |
|
|
173
|
+
| `agent_type` | `codex` |
|
|
174
|
+
| `session_id` | The Codex session id |
|
|
175
|
+
| `run_id` | The turn id, or the session id on hooks without a turn (`SessionStart`, `SessionEnd`) |
|
|
176
|
+
| `agent_id`, `deployment_id`, `deployment_name` | From the settings above |
|
|
177
|
+
| `tool_name` | The tool, on tool and permission hooks |
|
|
178
|
+
| `model`, `provider` | The model slug; the provider from the session transcript, or `openai` |
|
|
179
|
+
| `hook_decision` | `observe` |
|
|
180
|
+
| `event_data` | The Codex hook payload as received (`prompt`, `last_assistant_message`, `tool_input`, `tool_response`, `tool_use_id`, `token_usage`, `cwd`, `source`, `trigger`, and the subagent's `agent_id` and `agent_type`), plus the two keys below |
|
|
181
|
+
|
|
182
|
+
Two keys are added to `event_data`:
|
|
183
|
+
|
|
184
|
+
- `agentguard.export` is always `hooks`. On the `otel` path the app copies
|
|
185
|
+
some spans into `agentguard_hook_events` with the same `agent_type`; this
|
|
186
|
+
key is how a view tells a row written by the plugin from a copied one.
|
|
187
|
+
- `agentguard.duration_ms` is on closing events that had an opening event:
|
|
188
|
+
`post_tool_use`, `post_model_request`, `post_compact`, `subagent_ended` and
|
|
189
|
+
`session_end`. See [Pairing and timing](#pairing-and-timing).
|
|
190
|
+
|
|
191
|
+
The rows of one hook process go out in a single request with a 2 second
|
|
192
|
+
timeout, so `SessionEnd` and `Interrupt` finish inside Codex's 3 second limit.
|
|
193
|
+
|
|
194
|
+
Check what arrived with:
|
|
195
|
+
|
|
196
|
+
```sql
|
|
197
|
+
SELECT event_time, hook_name, session_id, run_id, tool_name, model
|
|
198
|
+
FROM table(ag.agentguard_hook_events)
|
|
199
|
+
WHERE agent_type = 'codex' AND json_value(event_data, '$."agentguard.export"') = 'hooks'
|
|
200
|
+
ORDER BY event_time DESC
|
|
201
|
+
LIMIT 20;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The app does not turn these rows into `agentguard_cim_event` and
|
|
205
|
+
`agentguard_cim_metrics` rows yet. That is
|
|
206
|
+
[timeplus-io/apps#71](https://github.com/timeplus-io/apps/issues/71); until it
|
|
207
|
+
ships, the `hooks` export fills `agentguard_hook_events` only.
|
|
208
|
+
|
|
209
|
+
## What gets captured
|
|
210
|
+
|
|
211
|
+
The plugin handles all 14 events in the
|
|
212
|
+
[Codex hooks reference](https://developers.openai.com/codex/hooks). On the
|
|
213
|
+
`otel` export, described in the rest of this section, each event becomes one
|
|
214
|
+
span, exported with the OTel service name `codex`, which the AgentGuard app
|
|
215
|
+
reports as the agent type. The `hooks` export handles the same 14 events; its
|
|
216
|
+
row format is under [Hook-event export](#hook-event-export).
|
|
217
|
+
|
|
218
|
+
| Codex hook | Emitted span | What it carries |
|
|
219
|
+
|---|---|---|
|
|
220
|
+
| `SessionStart` | `session_start` | Start source (`startup`, `resume`, ...); sent immediately, so a running session is visible |
|
|
221
|
+
| `SessionEnd` | `session` | The whole session, from `SessionStart` to `SessionEnd` |
|
|
222
|
+
| `UserPromptSubmit` | `user_prompt_submit` | The prompt (`input.value`) |
|
|
223
|
+
| `PreToolUse` | none (start time recorded) | |
|
|
224
|
+
| `PostToolUse` | `tool` | `tool.name`, `tool.parameters`, `output.value`, tool duration |
|
|
225
|
+
| `PreModelRequest` | `pre_model_request` | Request id, attempt number, kind |
|
|
226
|
+
| `PostModelRequest` | `post_model_request` | The LLM call: status, error, token usage, attempt duration |
|
|
227
|
+
| `Stop` | `stop` | The final assistant message (`output.value`) |
|
|
228
|
+
| `Interrupt` | `interrupt` | The interrupted turn |
|
|
229
|
+
| `SubagentStart` | `subagent_start` | Subagent id and type |
|
|
230
|
+
| `SubagentStop` | `subagent_stop` | Subagent id and type, its last message, subagent duration |
|
|
231
|
+
| `PermissionRequest` | `permission_request` | `tool.name`, `tool.parameters`, the request description |
|
|
232
|
+
| `PreCompact` | `pre_compact` | Trigger (`manual` or `auto`) |
|
|
233
|
+
| `PostCompact` | `post_compact` | Trigger, compaction duration |
|
|
234
|
+
|
|
235
|
+
### Span attributes
|
|
236
|
+
|
|
237
|
+
On every span, when Codex sends the field:
|
|
238
|
+
|
|
239
|
+
| Attribute | Source |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `session.id` | `session_id` |
|
|
242
|
+
| `run.id` | `turn_id` (turn-scoped hooks) |
|
|
243
|
+
| `agentguard.hook_name` | the hook, in snake case (`session_start`, `post_tool_use`, ...) |
|
|
244
|
+
| `llm.model_name` | `model` |
|
|
245
|
+
| `llm.provider` | `model_provider` from the first record of the session transcript; `openai` when the transcript cannot be read |
|
|
246
|
+
| `cwd` | `cwd`, the session's working directory |
|
|
247
|
+
| `codex.permission_mode` | `permission_mode` |
|
|
248
|
+
| `agentguard.subagent.id`, `agentguard.subagent.type` | `agent_id`, `agent_type` (subagent spans, and any other hook fired inside a subagent) |
|
|
249
|
+
|
|
250
|
+
Three spans carry the kind attribute the app's OpenInference views key on:
|
|
251
|
+
|
|
252
|
+
| Span | Kind attribute | The app derives |
|
|
253
|
+
|---|---|---|
|
|
254
|
+
| `post_model_request` | `openinference.span.kind=LLM` | `llm_request` / `llm_response` events, and the `llm.*` metrics |
|
|
255
|
+
| `tool` | `openinference.span.kind=TOOL` | `tool_invoke` / `tool_complete` events |
|
|
256
|
+
| `session` | `agentguard.span.kind=SESSION` | `session_start` / `session_end` events |
|
|
257
|
+
|
|
258
|
+
Per span:
|
|
259
|
+
|
|
260
|
+
| Attribute | Set on | Source |
|
|
261
|
+
|---|---|---|
|
|
262
|
+
| `source` | `session_start` | `source` |
|
|
263
|
+
| `codex.session.end_reason` | `session` | `reason` |
|
|
264
|
+
| `input.value` | `user_prompt_submit` | `prompt`, as JSON: `{"messages": [{"role": "user", "content": "..."}]}` |
|
|
265
|
+
| `tool.name`, `tool.parameters`, `output.value`, `tool_use_id` | `tool` | `tool_name`, `tool_input`, `tool_response`, `tool_use_id` |
|
|
266
|
+
| `task.id` | `tool`: the tool call id; model request spans: the request id; subagent spans: the subagent id | `tool_use_id`, `request_id`, `agent_id` |
|
|
267
|
+
| `codex.request.id`, `codex.request.attempt`, `codex.request.kind`, `codex.thread_id` | model request spans | `request_id`, `attempt_number`, `kind`, `thread_id` |
|
|
268
|
+
| `codex.request.status`, `codex.request.error` | `post_model_request` | `status` (`completed`, `failed`, `cancelled`), `error` |
|
|
269
|
+
| `llm.token_count.prompt`, `.completion`, `.total`, `.prompt_details.cache_read`, `.prompt_details.cache_write`, `.completion_details.reasoning` | `post_model_request`, when Codex reports usage | `token_usage` |
|
|
270
|
+
| `output.value` | `stop`, `subagent_stop` | `last_assistant_message` |
|
|
271
|
+
| `codex.stop_hook_active` | `stop`, `subagent_stop` | `stop_hook_active` |
|
|
272
|
+
| `codex.agent_transcript_path` | `subagent_stop` | `agent_transcript_path` |
|
|
273
|
+
| `tool.name`, `tool.parameters`, `codex.permission.description` | `permission_request` | `tool_name`, `tool_input`, `tool_input.description` |
|
|
274
|
+
| `codex.compact.trigger` | `pre_compact`, `post_compact` | `trigger` |
|
|
275
|
+
|
|
276
|
+
An attribute is left off the span when Codex does not send the field. A
|
|
277
|
+
`post_model_request` span with status `failed` also has the OTel span status
|
|
278
|
+
`ERROR`. Token counts are passed through as Codex reports them; whether
|
|
279
|
+
`input_tokens` already includes the cached tokens is not yet confirmed (see
|
|
280
|
+
[`docs/todo.md`](../docs/todo.md), item 0.4).
|
|
281
|
+
|
|
282
|
+
### Prompts, model requests and final responses
|
|
283
|
+
|
|
284
|
+
These are three separate records, so counting one does not count another:
|
|
285
|
+
|
|
286
|
+
- **Prompt** — one `user_prompt_submit` span per prompt. It is not an LLM
|
|
287
|
+
call: it has no duration and no token usage.
|
|
288
|
+
- **Model request** — one `pre_model_request` / `post_model_request` pair per
|
|
289
|
+
attempt. Only `post_model_request` is an LLM-kind span, so there is one LLM
|
|
290
|
+
call per attempt, with its real latency and token usage. A retry is a new
|
|
291
|
+
pair with the same `codex.request.id` and the next `codex.request.attempt`.
|
|
292
|
+
- **Final response** — one `stop` span per completed turn, with the assistant's
|
|
293
|
+
last message and no usage. `Stop` ends a turn, not the session. An
|
|
294
|
+
interrupted turn produces an `interrupt` span instead.
|
|
295
|
+
|
|
296
|
+
Subagent hooks carry the parent's `session.id`; `agentguard.subagent.id`
|
|
297
|
+
identifies the child.
|
|
298
|
+
|
|
299
|
+
### What the AgentGuard app shows
|
|
300
|
+
|
|
301
|
+
With the app's current OpenInference views (app 0.4.0), a Codex session gives:
|
|
302
|
+
|
|
303
|
+
- `agentguard_cim_event`: `session_start` / `session_end`, `llm_request` /
|
|
304
|
+
`llm_response` per model request, and `tool_invoke` / `tool_complete`, each
|
|
305
|
+
with agent type `codex`, the model, the provider, and `cwd` in
|
|
306
|
+
`raw_event_data`.
|
|
307
|
+
- `agentguard_cim_metrics`: `llm.call`, `llm.latency_ms` and the token metrics,
|
|
308
|
+
one set per model request.
|
|
309
|
+
|
|
310
|
+
The prompt text, the reply text and the live `session_start` are in
|
|
311
|
+
`otel_traces` (the `user_prompt_submit`, `stop` and `session_start` spans) but
|
|
312
|
+
the app does not turn them into CIM events yet; that is
|
|
313
|
+
[timeplus-io/apps#69](https://github.com/timeplus-io/apps/issues/69).
|
|
314
|
+
|
|
315
|
+
### Pairing and timing
|
|
316
|
+
|
|
317
|
+
Each hook is its own process, so opening events record their start time on
|
|
318
|
+
disk, in `~/.agentguard/<agent-id>/codex-starts/`, and the closing event's
|
|
319
|
+
span starts there. Tool calls are paired by session, turn and `tool_use_id`
|
|
320
|
+
(so overlapping tool calls do not overwrite each other's start time), model
|
|
321
|
+
requests by request id and attempt number, subagents by subagent id,
|
|
322
|
+
compactions by turn, and the session by session id. Without a matching opening event the
|
|
323
|
+
span is still emitted, with no duration. Entries nobody collected are removed
|
|
324
|
+
after 24 hours.
|
|
325
|
+
|
|
326
|
+
### Observe only
|
|
327
|
+
|
|
328
|
+
The plugin never answers a hook. It writes nothing to stdout and exits 0, which
|
|
329
|
+
Codex treats as "no opinion": `PermissionRequest` is recorded and the approval
|
|
330
|
+
decision stays with Codex's normal flow, `Stop` does not continue the turn, and
|
|
331
|
+
`PreCompact` does not stop a compaction. Hook events this plugin does not know
|
|
332
|
+
are ignored, so a newer Codex can add hooks without breaking it.
|
|
333
|
+
|
|
334
|
+
The model request hooks run once per attempt, and each hook is a new process
|
|
335
|
+
(about 0.15 s on a laptop with a reachable endpoint). Remove `PreModelRequest`
|
|
336
|
+
and `PostModelRequest` from your configuration if you do not need per-attempt
|
|
337
|
+
status and token usage.
|
|
338
|
+
|
|
339
|
+
## Development
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
make test # unit tests; the end-to-end OTel tests are skipped unless the SDK is installed
|
|
343
|
+
make build # sdist + wheel into dist/ (needs hatch)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
The plugin writes nothing to stdout and returns 0 even when it fails — any
|
|
347
|
+
error goes to stderr — so hook output cannot alter a Codex turn.
|
|
348
|
+
|
|
349
|
+
### Local end-to-end test
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
cd /path/to/AgentGuard
|
|
353
|
+
|
|
354
|
+
# 1. venv with the plugin and the in-repo SDK (drop `-e sdk/python` to use the PyPI release)
|
|
355
|
+
uv venv ~/venvs/agentguard-codex --python 3.12
|
|
356
|
+
uv pip install --python ~/venvs/agentguard-codex/bin/python \
|
|
357
|
+
-e sdk/python -e agents/codex/agentguard-plugin
|
|
358
|
+
|
|
359
|
+
# 2. merge this package's hooks.json into ~/.codex/hooks.json, replacing
|
|
360
|
+
# "command" with the venv's absolute path plus the plugin's env vars:
|
|
361
|
+
# "command": "env AGENTGUARD_AGENT_ID=codex-local \
|
|
362
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 \
|
|
363
|
+
# /Users/you/venvs/agentguard-codex/bin/agentguard-codex"
|
|
364
|
+
|
|
365
|
+
# 3. start Codex, run /hooks, review and trust the AgentGuard entries, quit
|
|
366
|
+
codex
|
|
367
|
+
|
|
368
|
+
# 4. run a turn
|
|
369
|
+
codex exec --skip-git-repo-check -s workspace-write \
|
|
370
|
+
"Run pwd, then create done.txt containing ok."
|
|
371
|
+
|
|
372
|
+
# 5. inspect the exported spans at the configured OTLP endpoint (the app's
|
|
373
|
+
# otel_traces, or any local OTLP collector), then remove the AgentGuard
|
|
374
|
+
# entries from ~/.codex/hooks.json
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## Publishing
|
|
378
|
+
|
|
379
|
+
Releases are published to PyPI by CI:
|
|
380
|
+
|
|
381
|
+
1. Bump `version` in `pyproject.toml` and `__version__` in `agentguard_codex/__init__.py`, and merge.
|
|
382
|
+
2. Publish a GitHub Release tagged `codex-plugin-v<version>` (for example `codex-plugin-v0.1.1`).
|
|
383
|
+
|
|
384
|
+
The `Publish Codex plugin` workflow tests, builds and uploads `timeplus-agentguard-codex-plugin`. It fails if the tag does not match the package version. Running it manually builds and validates without uploading; `make check` does the same locally (needs `hatch` and `twine`).
|