codex-codes 0.143.0

Typed Rust SDK for the OpenAI Codex agent CLI: serde models of the codex app-server JSON-RPC protocol, plus sync and async (Tokio) clients for multi-turn Codex agent sessions, tool calls, and approvals.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// AUTO-GENERATED by scripts/codegen_protocol.py — DO NOT EDIT BY HAND.

use serde_json::{json, Value};

/// Notification samples keyed by JSON-RPC method.
pub fn server_notification_samples() -> Vec<(&'static str, Value)> {
    vec![
        ("account/login/completed", json!({"success": false})),
        ("account/rateLimits/updated", json!({"rateLimits": {}})),
        ("account/updated", json!({})),
        ("app/list/updated", json!({"data": []})),
        (
            "command/exec/outputDelta",
            json!({"capReached": false, "deltaBase64": "x", "processId": "x", "stream": null}),
        ),
        ("configWarning", json!({"summary": "x"})),
        ("deprecationNotice", json!({"summary": "x"})),
        (
            "error",
            json!({"error": {"message": "x"}, "threadId": "x", "turnId": "x", "willRetry": false}),
        ),
        (
            "externalAgentConfig/import/completed",
            json!({"importId": "x", "itemTypeResults": []}),
        ),
        (
            "externalAgentConfig/import/progress",
            json!({"importId": "x", "itemTypeResults": []}),
        ),
        ("fs/changed", json!({"changedPaths": [], "watchId": "x"})),
        (
            "fuzzyFileSearch/sessionCompleted",
            json!({"sessionId": "x"}),
        ),
        (
            "fuzzyFileSearch/sessionUpdated",
            json!({"files": [], "query": "x", "sessionId": "x"}),
        ),
        ("guardianWarning", json!({"message": "x", "threadId": "x"})),
        (
            "hook/completed",
            json!({"run": {"displayOrder": 0, "entries": [], "eventName": "preToolUse", "executionMode": "sync", "handlerType": "command", "id": "x", "scope": "thread", "sourcePath": "x", "startedAt": 0, "status": "running"}, "threadId": "x"}),
        ),
        (
            "hook/started",
            json!({"run": {"displayOrder": 0, "entries": [], "eventName": "preToolUse", "executionMode": "sync", "handlerType": "command", "id": "x", "scope": "thread", "sourcePath": "x", "startedAt": 0, "status": "running"}, "threadId": "x"}),
        ),
        (
            "item/agentMessage/delta",
            json!({"delta": "x", "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/autoApprovalReview/completed",
            json!({"action": {"command": "x", "cwd": "x", "source": "shell", "type": "command"}, "completedAtMs": 0, "decisionSource": "agent", "review": {"status": "inProgress"}, "reviewId": "x", "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/autoApprovalReview/started",
            json!({"action": {"command": "x", "cwd": "x", "source": "shell", "type": "command"}, "review": {"status": "inProgress"}, "reviewId": "x", "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/commandExecution/outputDelta",
            json!({"delta": "x", "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/commandExecution/terminalInteraction",
            json!({"itemId": "x", "processId": "x", "stdin": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/completed",
            json!({"completedAtMs": 0, "item": {"content": [], "id": "x", "type": "userMessage"}, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/fileChange/outputDelta",
            json!({"delta": "x", "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/fileChange/patchUpdated",
            json!({"changes": [], "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/mcpToolCall/progress",
            json!({"itemId": "x", "message": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/plan/delta",
            json!({"delta": "x", "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/reasoning/summaryPartAdded",
            json!({"itemId": "x", "summaryIndex": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/reasoning/summaryTextDelta",
            json!({"delta": "x", "itemId": "x", "summaryIndex": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/reasoning/textDelta",
            json!({"contentIndex": 0, "delta": "x", "itemId": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/started",
            json!({"item": {"content": [], "id": "x", "type": "userMessage"}, "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "mcpServer/oauthLogin/completed",
            json!({"name": "x", "success": false}),
        ),
        (
            "mcpServer/startupStatus/updated",
            json!({"name": "x", "status": "starting"}),
        ),
        (
            "model/rerouted",
            json!({"fromModel": "x", "reason": "highRiskCyberActivity", "threadId": "x", "toModel": "x", "turnId": "x"}),
        ),
        (
            "model/safetyBuffering/updated",
            json!({"model": "x", "reasons": [], "showBufferingUi": false, "threadId": "x", "turnId": "x", "useCases": []}),
        ),
        (
            "model/verification",
            json!({"threadId": "x", "turnId": "x", "verifications": []}),
        ),
        (
            "process/exited",
            json!({"exitCode": 0, "processHandle": "x", "stderr": "x", "stderrCapReached": false, "stdout": "x", "stdoutCapReached": false}),
        ),
        (
            "process/outputDelta",
            json!({"capReached": false, "deltaBase64": "x", "processHandle": "x", "stream": null}),
        ),
        (
            "remoteControl/status/changed",
            json!({"installationId": "x", "serverName": "x", "status": "disabled"}),
        ),
        (
            "serverRequest/resolved",
            json!({"requestId": "x", "threadId": "x"}),
        ),
        ("skills/changed", json!({})),
        ("thread/archived", json!({"threadId": "x"})),
        ("thread/closed", json!({"threadId": "x"})),
        ("thread/compacted", json!({"threadId": "x", "turnId": "x"})),
        ("thread/deleted", json!({"threadId": "x"})),
        ("thread/goal/cleared", json!({"threadId": "x"})),
        (
            "thread/goal/updated",
            json!({"goal": {"createdAt": 0, "objective": "x", "status": "active", "threadId": "x", "timeUsedSeconds": 0, "tokensUsed": 0, "updatedAt": 0}, "threadId": "x"}),
        ),
        ("thread/name/updated", json!({"threadId": "x"})),
        ("thread/realtime/closed", json!({"threadId": "x"})),
        (
            "thread/realtime/error",
            json!({"message": "x", "threadId": "x"}),
        ),
        (
            "thread/realtime/itemAdded",
            json!({"item": null, "threadId": "x"}),
        ),
        (
            "thread/realtime/outputAudio/delta",
            json!({"audio": {"data": "x", "numChannels": 0, "sampleRate": 0}, "threadId": "x"}),
        ),
        ("thread/realtime/sdp", json!({"sdp": "x", "threadId": "x"})),
        (
            "thread/realtime/started",
            json!({"threadId": "x", "version": "v1"}),
        ),
        (
            "thread/realtime/transcript/delta",
            json!({"delta": "x", "role": "x", "threadId": "x"}),
        ),
        (
            "thread/realtime/transcript/done",
            json!({"role": "x", "text": "x", "threadId": "x"}),
        ),
        (
            "thread/settings/updated",
            json!({"threadId": "x", "threadSettings": {"approvalPolicy": "untrusted", "approvalsReviewer": "user", "collaborationMode": {"mode": "plan", "settings": {"model": "x"}}, "cwd": "x", "model": "x", "modelProvider": "x", "sandboxPolicy": {"type": "dangerFullAccess"}}}),
        ),
        (
            "thread/started",
            json!({"thread": {"cliVersion": "x", "createdAt": 0, "cwd": null, "ephemeral": false, "id": "x", "modelProvider": "x", "preview": "x", "sessionId": "x", "source": null, "status": null, "turns": [], "updatedAt": 0}}),
        ),
        (
            "thread/status/changed",
            json!({"status": {"type": "notLoaded"}, "threadId": "x"}),
        ),
        (
            "thread/tokenUsage/updated",
            json!({"threadId": "x", "tokenUsage": {"last": {"cachedInputTokens": 0, "inputTokens": 0, "outputTokens": 0, "reasoningOutputTokens": 0, "totalTokens": 0}, "total": {"cachedInputTokens": 0, "inputTokens": 0, "outputTokens": 0, "reasoningOutputTokens": 0, "totalTokens": 0}}, "turnId": "x"}),
        ),
        ("thread/unarchived", json!({"threadId": "x"})),
        (
            "turn/completed",
            json!({"threadId": "x", "turn": {"id": "x", "items": [], "status": "completed"}}),
        ),
        (
            "turn/diff/updated",
            json!({"diff": "x", "threadId": "x", "turnId": "x"}),
        ),
        (
            "turn/moderationMetadata",
            json!({"metadata": null, "threadId": "x", "turnId": "x"}),
        ),
        (
            "turn/plan/updated",
            json!({"plan": [], "threadId": "x", "turnId": "x"}),
        ),
        (
            "turn/started",
            json!({"threadId": "x", "turn": {"id": "x", "items": [], "status": "completed"}}),
        ),
        ("warning", json!({"message": "x"})),
        (
            "windows/worldWritableWarning",
            json!({"extraCount": 0, "failedScan": false, "samplePaths": []}),
        ),
        (
            "windowsSandbox/setupCompleted",
            json!({"mode": "elevated", "success": false}),
        ),
    ]
}

/// Client-request samples keyed by JSON-RPC method.
pub fn client_request_samples() -> Vec<(&'static str, Value)> {
    vec![
        ("account/login/cancel", json!({"loginId": "x"})),
        (
            "account/login/start",
            json!({"apiKey": "x", "type": "apiKey"}),
        ),
        ("account/logout", json!({})),
        (
            "account/rateLimitResetCredit/consume",
            json!({"idempotencyKey": "x"}),
        ),
        ("account/rateLimits/read", json!({})),
        ("account/read", json!({})),
        (
            "account/sendAddCreditsNudgeEmail",
            json!({"creditType": "credits"}),
        ),
        ("account/usage/read", json!({})),
        ("account/workspaceMessages/read", json!({})),
        ("app/list", json!({})),
        ("command/exec", json!({"command": []})),
        (
            "command/exec/resize",
            json!({"processId": "x", "size": null}),
        ),
        ("command/exec/terminate", json!({"processId": "x"})),
        ("command/exec/write", json!({"processId": "x"})),
        ("config/batchWrite", json!({"edits": []})),
        ("config/mcpServer/reload", json!({})),
        ("config/read", json!({})),
        (
            "config/value/write",
            json!({"keyPath": "x", "mergeStrategy": "replace", "value": null}),
        ),
        ("configRequirements/read", json!({})),
        (
            "experimentalFeature/enablement/set",
            json!({"enablement": {}}),
        ),
        ("experimentalFeature/list", json!({})),
        ("externalAgentConfig/detect", json!({})),
        ("externalAgentConfig/import", json!({"migrationItems": []})),
        ("externalAgentConfig/import/readHistories", json!({})),
        ("feedback/upload", json!({"classification": "x"})),
        (
            "fs/copy",
            json!({"destinationPath": null, "sourcePath": null}),
        ),
        ("fs/createDirectory", json!({"path": null})),
        ("fs/getMetadata", json!({"path": null})),
        ("fs/readDirectory", json!({"path": null})),
        ("fs/readFile", json!({"path": null})),
        ("fs/remove", json!({"path": null})),
        ("fs/unwatch", json!({"watchId": "x"})),
        ("fs/watch", json!({"path": null, "watchId": "x"})),
        ("fs/writeFile", json!({"dataBase64": "x", "path": null})),
        ("fuzzyFileSearch", json!({"query": "x", "roots": []})),
        ("hooks/list", json!({})),
        (
            "initialize",
            json!({"clientInfo": {"name": "x", "version": "x"}}),
        ),
        ("marketplace/add", json!({"source": "x"})),
        ("marketplace/remove", json!({"marketplaceName": "x"})),
        ("marketplace/upgrade", json!({})),
        ("mcpServer/oauth/login", json!({"name": "x"})),
        (
            "mcpServer/resource/read",
            json!({"server": "x", "uri": "x"}),
        ),
        (
            "mcpServer/tool/call",
            json!({"server": "x", "threadId": "x", "tool": "x"}),
        ),
        ("mcpServerStatus/list", json!({})),
        ("model/list", json!({})),
        ("modelProvider/capabilities/read", json!({})),
        ("permissionProfile/list", json!({})),
        ("plugin/install", json!({"pluginName": "x"})),
        ("plugin/installed", json!({})),
        ("plugin/list", json!({})),
        ("plugin/read", json!({"pluginName": "x"})),
        ("plugin/share/checkout", json!({"remotePluginId": "x"})),
        ("plugin/share/delete", json!({"remotePluginId": "x"})),
        ("plugin/share/list", json!({})),
        ("plugin/share/save", json!({"pluginPath": "x"})),
        (
            "plugin/share/updateTargets",
            json!({"discoverability": "UNLISTED", "remotePluginId": "x", "shareTargets": []}),
        ),
        (
            "plugin/skill/read",
            json!({"remoteMarketplaceName": "x", "remotePluginId": "x", "skillName": "x"}),
        ),
        ("plugin/uninstall", json!({"pluginId": "x"})),
        (
            "review/start",
            json!({"target": {"type": "uncommittedChanges"}, "threadId": "x"}),
        ),
        ("skills/config/write", json!({"enabled": false})),
        ("skills/extraRoots/set", json!({"extraRoots": []})),
        ("skills/list", json!({})),
        (
            "thread/approveGuardianDeniedAction",
            json!({"event": null, "threadId": "x"}),
        ),
        ("thread/archive", json!({"threadId": "x"})),
        ("thread/compact/start", json!({"threadId": "x"})),
        ("thread/delete", json!({"threadId": "x"})),
        ("thread/fork", json!({"threadId": "x"})),
        ("thread/goal/clear", json!({"threadId": "x"})),
        ("thread/goal/get", json!({"threadId": "x"})),
        ("thread/goal/set", json!({"threadId": "x"})),
        ("thread/inject_items", json!({"items": [], "threadId": "x"})),
        ("thread/list", json!({})),
        ("thread/loaded/list", json!({})),
        ("thread/metadata/update", json!({"threadId": "x"})),
        ("thread/name/set", json!({"name": "x", "threadId": "x"})),
        ("thread/read", json!({"threadId": "x"})),
        ("thread/resume", json!({"threadId": "x"})),
        ("thread/rollback", json!({"numTurns": 0, "threadId": "x"})),
        (
            "thread/shellCommand",
            json!({"command": "x", "threadId": "x"}),
        ),
        ("thread/start", json!({})),
        ("thread/unarchive", json!({"threadId": "x"})),
        ("thread/unsubscribe", json!({"threadId": "x"})),
        ("turn/interrupt", json!({"threadId": "x", "turnId": "x"})),
        ("turn/start", json!({"input": [], "threadId": "x"})),
        (
            "turn/steer",
            json!({"expectedTurnId": "x", "input": [], "threadId": "x"}),
        ),
        ("windowsSandbox/readiness", json!({})),
        ("windowsSandbox/setupStart", json!({"mode": "elevated"})),
    ]
}

/// Server-request (approval flow) samples keyed by JSON-RPC method.
pub fn server_request_samples() -> Vec<(&'static str, Value)> {
    vec![
        (
            "account/chatgptAuthTokens/refresh",
            json!({"reason": "unauthorized"}),
        ),
        (
            "applyPatchApproval",
            json!({"callId": "x", "conversationId": "x", "fileChanges": {}}),
        ),
        ("attestation/generate", json!({})),
        (
            "execCommandApproval",
            json!({"callId": "x", "command": [], "conversationId": "x", "cwd": "x", "parsedCmd": []}),
        ),
        (
            "item/commandExecution/requestApproval",
            json!({"itemId": "x", "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/fileChange/requestApproval",
            json!({"itemId": "x", "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/permissions/requestApproval",
            json!({"cwd": "x", "itemId": "x", "permissions": {}, "startedAtMs": 0, "threadId": "x", "turnId": "x"}),
        ),
        (
            "item/tool/call",
            json!({"arguments": null, "callId": "x", "threadId": "x", "tool": "x", "turnId": "x"}),
        ),
        (
            "item/tool/requestUserInput",
            json!({"itemId": "x", "questions": [], "threadId": "x", "turnId": "x"}),
        ),
        (
            "mcpServer/elicitation/request",
            json!({"message": "x", "mode": "form", "requestedSchema": {"properties": {}, "type": "object"}}),
        ),
    ]
}