axexec 1.0.0

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.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +196 -0
  3. package/bin/axexec +17 -0
  4. package/dist/agents/claude-code/adapter.d.ts +6 -0
  5. package/dist/agents/claude-code/adapter.js +71 -0
  6. package/dist/agents/claude-code/parse-event.d.ts +16 -0
  7. package/dist/agents/claude-code/parse-event.js +185 -0
  8. package/dist/agents/claude-code/types.d.ts +180 -0
  9. package/dist/agents/claude-code/types.js +112 -0
  10. package/dist/agents/codex/adapter.d.ts +6 -0
  11. package/dist/agents/codex/adapter.js +62 -0
  12. package/dist/agents/codex/item-parsers.d.ts +17 -0
  13. package/dist/agents/codex/item-parsers.js +126 -0
  14. package/dist/agents/codex/parse-event.d.ts +38 -0
  15. package/dist/agents/codex/parse-event.js +141 -0
  16. package/dist/agents/codex/types.d.ts +407 -0
  17. package/dist/agents/codex/types.js +188 -0
  18. package/dist/agents/copilot/adapter.d.ts +11 -0
  19. package/dist/agents/copilot/adapter.js +81 -0
  20. package/dist/agents/copilot/parse-event.d.ts +20 -0
  21. package/dist/agents/copilot/parse-event.js +137 -0
  22. package/dist/agents/copilot/stream-session.d.ts +10 -0
  23. package/dist/agents/copilot/stream-session.js +120 -0
  24. package/dist/agents/copilot/tail-file.d.ts +11 -0
  25. package/dist/agents/copilot/tail-file.js +52 -0
  26. package/dist/agents/copilot/transform-event.d.ts +19 -0
  27. package/dist/agents/copilot/transform-event.js +100 -0
  28. package/dist/agents/copilot/types.d.ts +320 -0
  29. package/dist/agents/copilot/types.js +220 -0
  30. package/dist/agents/copilot/watch-session.d.ts +26 -0
  31. package/dist/agents/copilot/watch-session.js +186 -0
  32. package/dist/agents/gemini/adapter.d.ts +6 -0
  33. package/dist/agents/gemini/adapter.js +78 -0
  34. package/dist/agents/gemini/parse-event.d.ts +18 -0
  35. package/dist/agents/gemini/parse-event.js +144 -0
  36. package/dist/agents/gemini/types.d.ts +162 -0
  37. package/dist/agents/gemini/types.js +103 -0
  38. package/dist/agents/opencode/adapter.d.ts +16 -0
  39. package/dist/agents/opencode/adapter.js +142 -0
  40. package/dist/agents/opencode/cleanup-session.d.ts +17 -0
  41. package/dist/agents/opencode/cleanup-session.js +41 -0
  42. package/dist/agents/opencode/create-session-start-event.d.ts +18 -0
  43. package/dist/agents/opencode/create-session-start-event.js +24 -0
  44. package/dist/agents/opencode/detect-empty-session.d.ts +25 -0
  45. package/dist/agents/opencode/detect-empty-session.js +42 -0
  46. package/dist/agents/opencode/map-error-to-event.d.ts +10 -0
  47. package/dist/agents/opencode/map-error-to-event.js +55 -0
  48. package/dist/agents/opencode/parse-message-part.d.ts +24 -0
  49. package/dist/agents/opencode/parse-message-part.js +112 -0
  50. package/dist/agents/opencode/parse-sse-event.d.ts +23 -0
  51. package/dist/agents/opencode/parse-sse-event.js +125 -0
  52. package/dist/agents/opencode/process-sse-events.d.ts +24 -0
  53. package/dist/agents/opencode/process-sse-events.js +66 -0
  54. package/dist/agents/opencode/server-types.d.ts +509 -0
  55. package/dist/agents/opencode/server-types.js +293 -0
  56. package/dist/agents/opencode/session-api.d.ts +56 -0
  57. package/dist/agents/opencode/session-api.js +151 -0
  58. package/dist/agents/opencode/spawn-server.d.ts +29 -0
  59. package/dist/agents/opencode/spawn-server.js +95 -0
  60. package/dist/agents/opencode/sse-client.d.ts +33 -0
  61. package/dist/agents/opencode/sse-client.js +145 -0
  62. package/dist/agents/registry.d.ts +15 -0
  63. package/dist/agents/registry.js +24 -0
  64. package/dist/cli.d.ts +15 -0
  65. package/dist/cli.js +119 -0
  66. package/dist/credentials/get-credential-environment.d.ts +13 -0
  67. package/dist/credentials/get-credential-environment.js +46 -0
  68. package/dist/credentials/install-credentials.d.ts +27 -0
  69. package/dist/credentials/install-credentials.js +102 -0
  70. package/dist/credentials/save-json-file.d.ts +11 -0
  71. package/dist/credentials/save-json-file.js +21 -0
  72. package/dist/credentials/types.d.ts +24 -0
  73. package/dist/credentials/types.js +4 -0
  74. package/dist/credentials/write-agent-credentials.d.ts +36 -0
  75. package/dist/credentials/write-agent-credentials.js +91 -0
  76. package/dist/determine-session-success.d.ts +15 -0
  77. package/dist/determine-session-success.js +25 -0
  78. package/dist/format-event-tsv.d.ts +23 -0
  79. package/dist/format-event-tsv.js +136 -0
  80. package/dist/parse-credentials.d.ts +13 -0
  81. package/dist/parse-credentials.js +63 -0
  82. package/dist/parse-iso-timestamp.d.ts +21 -0
  83. package/dist/parse-iso-timestamp.js +37 -0
  84. package/dist/resolve-binary.d.ts +29 -0
  85. package/dist/resolve-binary.js +46 -0
  86. package/dist/resolve-output-mode.d.ts +39 -0
  87. package/dist/resolve-output-mode.js +39 -0
  88. package/dist/run-agent.d.ts +32 -0
  89. package/dist/run-agent.js +146 -0
  90. package/dist/stream-agent.d.ts +20 -0
  91. package/dist/stream-agent.js +207 -0
  92. package/dist/types/adapter.d.ts +101 -0
  93. package/dist/types/adapter.js +14 -0
  94. package/dist/types/events.d.ts +82 -0
  95. package/dist/types/events.js +13 -0
  96. package/dist/types/options.d.ts +41 -0
  97. package/dist/types/options.js +4 -0
  98. package/dist/validate-agent.d.ts +20 -0
  99. package/dist/validate-agent.js +50 -0
  100. package/dist/write-event.d.ts +23 -0
  101. package/dist/write-event.js +43 -0
  102. package/package.json +79 -0
@@ -0,0 +1,407 @@
1
+ /**
2
+ * Raw event types from Codex CLI's JSONL stream.
3
+ *
4
+ * These types represent the raw output from:
5
+ * `codex exec --json "..."`
6
+ *
7
+ * The parser transforms these into normalized {@link AxexecEvent} types.
8
+ */
9
+ import { z } from "zod";
10
+ /** Thread started event - emitted when a new thread begins */
11
+ declare const CodexThreadStartedEvent: z.ZodObject<{
12
+ type: z.ZodLiteral<"thread.started">;
13
+ thread_id: z.ZodString;
14
+ }, z.core.$strip>;
15
+ type CodexThreadStartedEvent = z.infer<typeof CodexThreadStartedEvent>;
16
+ /** Turn completed event - emitted when a turn finishes successfully */
17
+ declare const CodexTurnCompletedEvent: z.ZodObject<{
18
+ type: z.ZodLiteral<"turn.completed">;
19
+ usage: z.ZodObject<{
20
+ input_tokens: z.ZodNumber;
21
+ cached_input_tokens: z.ZodNumber;
22
+ output_tokens: z.ZodNumber;
23
+ }, z.core.$strip>;
24
+ }, z.core.$strip>;
25
+ type CodexTurnCompletedEvent = z.infer<typeof CodexTurnCompletedEvent>;
26
+ /** Turn failed event - emitted when a turn fails */
27
+ declare const CodexTurnFailedEvent: z.ZodObject<{
28
+ type: z.ZodLiteral<"turn.failed">;
29
+ error: z.ZodObject<{
30
+ message: z.ZodString;
31
+ }, z.core.$strip>;
32
+ }, z.core.$strip>;
33
+ type CodexTurnFailedEvent = z.infer<typeof CodexTurnFailedEvent>;
34
+ /** Item started event - emitted when an item begins processing */
35
+ declare const CodexItemStartedEvent: z.ZodObject<{
36
+ type: z.ZodLiteral<"item.started">;
37
+ item: z.ZodDiscriminatedUnion<[z.ZodObject<{
38
+ id: z.ZodString;
39
+ type: z.ZodLiteral<"command_execution">;
40
+ command: z.ZodString;
41
+ aggregated_output: z.ZodString;
42
+ exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
43
+ status: z.ZodEnum<{
44
+ in_progress: "in_progress";
45
+ completed: "completed";
46
+ failed: "failed";
47
+ }>;
48
+ }, z.core.$strip>, z.ZodObject<{
49
+ id: z.ZodString;
50
+ type: z.ZodLiteral<"mcp_tool_call">;
51
+ server: z.ZodString;
52
+ tool: z.ZodString;
53
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
54
+ result: z.ZodOptional<z.ZodUnknown>;
55
+ error: z.ZodOptional<z.ZodString>;
56
+ status: z.ZodEnum<{
57
+ in_progress: "in_progress";
58
+ completed: "completed";
59
+ failed: "failed";
60
+ }>;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ id: z.ZodString;
63
+ type: z.ZodLiteral<"file_change">;
64
+ changes: z.ZodArray<z.ZodObject<{
65
+ path: z.ZodString;
66
+ kind: z.ZodEnum<{
67
+ add: "add";
68
+ delete: "delete";
69
+ update: "update";
70
+ }>;
71
+ }, z.core.$strip>>;
72
+ status: z.ZodEnum<{
73
+ completed: "completed";
74
+ failed: "failed";
75
+ }>;
76
+ }, z.core.$strip>, z.ZodObject<{
77
+ id: z.ZodString;
78
+ type: z.ZodLiteral<"agent_message">;
79
+ text: z.ZodString;
80
+ }, z.core.$strip>, z.ZodObject<{
81
+ id: z.ZodString;
82
+ type: z.ZodLiteral<"reasoning">;
83
+ text: z.ZodString;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ id: z.ZodString;
86
+ type: z.ZodLiteral<"web_search">;
87
+ query: z.ZodString;
88
+ }, z.core.$strip>, z.ZodObject<{
89
+ id: z.ZodString;
90
+ type: z.ZodLiteral<"todo_list">;
91
+ items: z.ZodArray<z.ZodObject<{
92
+ text: z.ZodString;
93
+ completed: z.ZodBoolean;
94
+ }, z.core.$strip>>;
95
+ }, z.core.$strip>, z.ZodObject<{
96
+ id: z.ZodString;
97
+ type: z.ZodLiteral<"error">;
98
+ message: z.ZodString;
99
+ }, z.core.$strip>], "type">;
100
+ }, z.core.$strip>;
101
+ type CodexItemStartedEvent = z.infer<typeof CodexItemStartedEvent>;
102
+ /** Item completed event - emitted when an item finishes */
103
+ declare const CodexItemCompletedEvent: z.ZodObject<{
104
+ type: z.ZodLiteral<"item.completed">;
105
+ item: z.ZodDiscriminatedUnion<[z.ZodObject<{
106
+ id: z.ZodString;
107
+ type: z.ZodLiteral<"command_execution">;
108
+ command: z.ZodString;
109
+ aggregated_output: z.ZodString;
110
+ exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
111
+ status: z.ZodEnum<{
112
+ in_progress: "in_progress";
113
+ completed: "completed";
114
+ failed: "failed";
115
+ }>;
116
+ }, z.core.$strip>, z.ZodObject<{
117
+ id: z.ZodString;
118
+ type: z.ZodLiteral<"mcp_tool_call">;
119
+ server: z.ZodString;
120
+ tool: z.ZodString;
121
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
122
+ result: z.ZodOptional<z.ZodUnknown>;
123
+ error: z.ZodOptional<z.ZodString>;
124
+ status: z.ZodEnum<{
125
+ in_progress: "in_progress";
126
+ completed: "completed";
127
+ failed: "failed";
128
+ }>;
129
+ }, z.core.$strip>, z.ZodObject<{
130
+ id: z.ZodString;
131
+ type: z.ZodLiteral<"file_change">;
132
+ changes: z.ZodArray<z.ZodObject<{
133
+ path: z.ZodString;
134
+ kind: z.ZodEnum<{
135
+ add: "add";
136
+ delete: "delete";
137
+ update: "update";
138
+ }>;
139
+ }, z.core.$strip>>;
140
+ status: z.ZodEnum<{
141
+ completed: "completed";
142
+ failed: "failed";
143
+ }>;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ id: z.ZodString;
146
+ type: z.ZodLiteral<"agent_message">;
147
+ text: z.ZodString;
148
+ }, z.core.$strip>, z.ZodObject<{
149
+ id: z.ZodString;
150
+ type: z.ZodLiteral<"reasoning">;
151
+ text: z.ZodString;
152
+ }, z.core.$strip>, z.ZodObject<{
153
+ id: z.ZodString;
154
+ type: z.ZodLiteral<"web_search">;
155
+ query: z.ZodString;
156
+ }, z.core.$strip>, z.ZodObject<{
157
+ id: z.ZodString;
158
+ type: z.ZodLiteral<"todo_list">;
159
+ items: z.ZodArray<z.ZodObject<{
160
+ text: z.ZodString;
161
+ completed: z.ZodBoolean;
162
+ }, z.core.$strip>>;
163
+ }, z.core.$strip>, z.ZodObject<{
164
+ id: z.ZodString;
165
+ type: z.ZodLiteral<"error">;
166
+ message: z.ZodString;
167
+ }, z.core.$strip>], "type">;
168
+ }, z.core.$strip>;
169
+ type CodexItemCompletedEvent = z.infer<typeof CodexItemCompletedEvent>;
170
+ /** Error event - top-level error */
171
+ declare const CodexErrorEvent: z.ZodObject<{
172
+ type: z.ZodLiteral<"error">;
173
+ message: z.ZodString;
174
+ }, z.core.$strip>;
175
+ type CodexErrorEvent = z.infer<typeof CodexErrorEvent>;
176
+ /** Union of all Codex CLI event types */
177
+ declare const CodexEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
178
+ type: z.ZodLiteral<"thread.started">;
179
+ thread_id: z.ZodString;
180
+ }, z.core.$strip>, z.ZodObject<{
181
+ type: z.ZodLiteral<"turn.started">;
182
+ }, z.core.$strip>, z.ZodObject<{
183
+ type: z.ZodLiteral<"turn.completed">;
184
+ usage: z.ZodObject<{
185
+ input_tokens: z.ZodNumber;
186
+ cached_input_tokens: z.ZodNumber;
187
+ output_tokens: z.ZodNumber;
188
+ }, z.core.$strip>;
189
+ }, z.core.$strip>, z.ZodObject<{
190
+ type: z.ZodLiteral<"turn.failed">;
191
+ error: z.ZodObject<{
192
+ message: z.ZodString;
193
+ }, z.core.$strip>;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ type: z.ZodLiteral<"item.started">;
196
+ item: z.ZodDiscriminatedUnion<[z.ZodObject<{
197
+ id: z.ZodString;
198
+ type: z.ZodLiteral<"command_execution">;
199
+ command: z.ZodString;
200
+ aggregated_output: z.ZodString;
201
+ exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
202
+ status: z.ZodEnum<{
203
+ in_progress: "in_progress";
204
+ completed: "completed";
205
+ failed: "failed";
206
+ }>;
207
+ }, z.core.$strip>, z.ZodObject<{
208
+ id: z.ZodString;
209
+ type: z.ZodLiteral<"mcp_tool_call">;
210
+ server: z.ZodString;
211
+ tool: z.ZodString;
212
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
213
+ result: z.ZodOptional<z.ZodUnknown>;
214
+ error: z.ZodOptional<z.ZodString>;
215
+ status: z.ZodEnum<{
216
+ in_progress: "in_progress";
217
+ completed: "completed";
218
+ failed: "failed";
219
+ }>;
220
+ }, z.core.$strip>, z.ZodObject<{
221
+ id: z.ZodString;
222
+ type: z.ZodLiteral<"file_change">;
223
+ changes: z.ZodArray<z.ZodObject<{
224
+ path: z.ZodString;
225
+ kind: z.ZodEnum<{
226
+ add: "add";
227
+ delete: "delete";
228
+ update: "update";
229
+ }>;
230
+ }, z.core.$strip>>;
231
+ status: z.ZodEnum<{
232
+ completed: "completed";
233
+ failed: "failed";
234
+ }>;
235
+ }, z.core.$strip>, z.ZodObject<{
236
+ id: z.ZodString;
237
+ type: z.ZodLiteral<"agent_message">;
238
+ text: z.ZodString;
239
+ }, z.core.$strip>, z.ZodObject<{
240
+ id: z.ZodString;
241
+ type: z.ZodLiteral<"reasoning">;
242
+ text: z.ZodString;
243
+ }, z.core.$strip>, z.ZodObject<{
244
+ id: z.ZodString;
245
+ type: z.ZodLiteral<"web_search">;
246
+ query: z.ZodString;
247
+ }, z.core.$strip>, z.ZodObject<{
248
+ id: z.ZodString;
249
+ type: z.ZodLiteral<"todo_list">;
250
+ items: z.ZodArray<z.ZodObject<{
251
+ text: z.ZodString;
252
+ completed: z.ZodBoolean;
253
+ }, z.core.$strip>>;
254
+ }, z.core.$strip>, z.ZodObject<{
255
+ id: z.ZodString;
256
+ type: z.ZodLiteral<"error">;
257
+ message: z.ZodString;
258
+ }, z.core.$strip>], "type">;
259
+ }, z.core.$strip>, z.ZodObject<{
260
+ type: z.ZodLiteral<"item.updated">;
261
+ item: z.ZodDiscriminatedUnion<[z.ZodObject<{
262
+ id: z.ZodString;
263
+ type: z.ZodLiteral<"command_execution">;
264
+ command: z.ZodString;
265
+ aggregated_output: z.ZodString;
266
+ exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
267
+ status: z.ZodEnum<{
268
+ in_progress: "in_progress";
269
+ completed: "completed";
270
+ failed: "failed";
271
+ }>;
272
+ }, z.core.$strip>, z.ZodObject<{
273
+ id: z.ZodString;
274
+ type: z.ZodLiteral<"mcp_tool_call">;
275
+ server: z.ZodString;
276
+ tool: z.ZodString;
277
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
278
+ result: z.ZodOptional<z.ZodUnknown>;
279
+ error: z.ZodOptional<z.ZodString>;
280
+ status: z.ZodEnum<{
281
+ in_progress: "in_progress";
282
+ completed: "completed";
283
+ failed: "failed";
284
+ }>;
285
+ }, z.core.$strip>, z.ZodObject<{
286
+ id: z.ZodString;
287
+ type: z.ZodLiteral<"file_change">;
288
+ changes: z.ZodArray<z.ZodObject<{
289
+ path: z.ZodString;
290
+ kind: z.ZodEnum<{
291
+ add: "add";
292
+ delete: "delete";
293
+ update: "update";
294
+ }>;
295
+ }, z.core.$strip>>;
296
+ status: z.ZodEnum<{
297
+ completed: "completed";
298
+ failed: "failed";
299
+ }>;
300
+ }, z.core.$strip>, z.ZodObject<{
301
+ id: z.ZodString;
302
+ type: z.ZodLiteral<"agent_message">;
303
+ text: z.ZodString;
304
+ }, z.core.$strip>, z.ZodObject<{
305
+ id: z.ZodString;
306
+ type: z.ZodLiteral<"reasoning">;
307
+ text: z.ZodString;
308
+ }, z.core.$strip>, z.ZodObject<{
309
+ id: z.ZodString;
310
+ type: z.ZodLiteral<"web_search">;
311
+ query: z.ZodString;
312
+ }, z.core.$strip>, z.ZodObject<{
313
+ id: z.ZodString;
314
+ type: z.ZodLiteral<"todo_list">;
315
+ items: z.ZodArray<z.ZodObject<{
316
+ text: z.ZodString;
317
+ completed: z.ZodBoolean;
318
+ }, z.core.$strip>>;
319
+ }, z.core.$strip>, z.ZodObject<{
320
+ id: z.ZodString;
321
+ type: z.ZodLiteral<"error">;
322
+ message: z.ZodString;
323
+ }, z.core.$strip>], "type">;
324
+ }, z.core.$strip>, z.ZodObject<{
325
+ type: z.ZodLiteral<"item.completed">;
326
+ item: z.ZodDiscriminatedUnion<[z.ZodObject<{
327
+ id: z.ZodString;
328
+ type: z.ZodLiteral<"command_execution">;
329
+ command: z.ZodString;
330
+ aggregated_output: z.ZodString;
331
+ exit_code: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
332
+ status: z.ZodEnum<{
333
+ in_progress: "in_progress";
334
+ completed: "completed";
335
+ failed: "failed";
336
+ }>;
337
+ }, z.core.$strip>, z.ZodObject<{
338
+ id: z.ZodString;
339
+ type: z.ZodLiteral<"mcp_tool_call">;
340
+ server: z.ZodString;
341
+ tool: z.ZodString;
342
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
343
+ result: z.ZodOptional<z.ZodUnknown>;
344
+ error: z.ZodOptional<z.ZodString>;
345
+ status: z.ZodEnum<{
346
+ in_progress: "in_progress";
347
+ completed: "completed";
348
+ failed: "failed";
349
+ }>;
350
+ }, z.core.$strip>, z.ZodObject<{
351
+ id: z.ZodString;
352
+ type: z.ZodLiteral<"file_change">;
353
+ changes: z.ZodArray<z.ZodObject<{
354
+ path: z.ZodString;
355
+ kind: z.ZodEnum<{
356
+ add: "add";
357
+ delete: "delete";
358
+ update: "update";
359
+ }>;
360
+ }, z.core.$strip>>;
361
+ status: z.ZodEnum<{
362
+ completed: "completed";
363
+ failed: "failed";
364
+ }>;
365
+ }, z.core.$strip>, z.ZodObject<{
366
+ id: z.ZodString;
367
+ type: z.ZodLiteral<"agent_message">;
368
+ text: z.ZodString;
369
+ }, z.core.$strip>, z.ZodObject<{
370
+ id: z.ZodString;
371
+ type: z.ZodLiteral<"reasoning">;
372
+ text: z.ZodString;
373
+ }, z.core.$strip>, z.ZodObject<{
374
+ id: z.ZodString;
375
+ type: z.ZodLiteral<"web_search">;
376
+ query: z.ZodString;
377
+ }, z.core.$strip>, z.ZodObject<{
378
+ id: z.ZodString;
379
+ type: z.ZodLiteral<"todo_list">;
380
+ items: z.ZodArray<z.ZodObject<{
381
+ text: z.ZodString;
382
+ completed: z.ZodBoolean;
383
+ }, z.core.$strip>>;
384
+ }, z.core.$strip>, z.ZodObject<{
385
+ id: z.ZodString;
386
+ type: z.ZodLiteral<"error">;
387
+ message: z.ZodString;
388
+ }, z.core.$strip>], "type">;
389
+ }, z.core.$strip>, z.ZodObject<{
390
+ type: z.ZodLiteral<"error">;
391
+ message: z.ZodString;
392
+ }, z.core.$strip>], "type">;
393
+ type CodexEvent = z.infer<typeof CodexEvent>;
394
+ /** Type guard for thread.started events */
395
+ declare function isThreadStartedEvent(event: CodexEvent): event is CodexThreadStartedEvent;
396
+ /** Type guard for turn.completed events */
397
+ declare function isTurnCompletedEvent(event: CodexEvent): event is CodexTurnCompletedEvent;
398
+ /** Type guard for turn.failed events */
399
+ declare function isTurnFailedEvent(event: CodexEvent): event is CodexTurnFailedEvent;
400
+ /** Type guard for item.started events */
401
+ declare function isItemStartedEvent(event: CodexEvent): event is CodexItemStartedEvent;
402
+ /** Type guard for item.completed events */
403
+ declare function isItemCompletedEvent(event: CodexEvent): event is CodexItemCompletedEvent;
404
+ /** Type guard for error events */
405
+ declare function isErrorEvent(event: CodexEvent): event is CodexErrorEvent;
406
+ export { CodexEvent, isErrorEvent, isItemCompletedEvent, isItemStartedEvent, isThreadStartedEvent, isTurnCompletedEvent, isTurnFailedEvent, };
407
+ export type { CodexErrorEvent, CodexItemCompletedEvent, CodexItemStartedEvent, CodexThreadStartedEvent, CodexTurnCompletedEvent, CodexTurnFailedEvent, };
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Raw event types from Codex CLI's JSONL stream.
3
+ *
4
+ * These types represent the raw output from:
5
+ * `codex exec --json "..."`
6
+ *
7
+ * The parser transforms these into normalized {@link AxexecEvent} types.
8
+ */
9
+ import { z } from "zod";
10
+ // =============================================================================
11
+ // Thread Item Types (discriminated union)
12
+ // =============================================================================
13
+ /** Status for items that can be in progress */
14
+ const CodexItemStatus = z.enum(["in_progress", "completed", "failed"]);
15
+ /** Command execution item - shell command being executed */
16
+ const CodexCommandExecutionItem = z.object({
17
+ id: z.string(),
18
+ type: z.literal("command_execution"),
19
+ command: z.string(),
20
+ aggregated_output: z.string(),
21
+ exit_code: z.number().nullish(),
22
+ status: CodexItemStatus,
23
+ });
24
+ /** MCP tool call item - MCP server tool invocation */
25
+ const CodexMcpToolCallItem = z.object({
26
+ id: z.string(),
27
+ type: z.literal("mcp_tool_call"),
28
+ server: z.string(),
29
+ tool: z.string(),
30
+ arguments: z.record(z.string(), z.unknown()),
31
+ result: z.unknown().optional(),
32
+ error: z.string().optional(),
33
+ status: CodexItemStatus,
34
+ });
35
+ /** File change kind */
36
+ const CodexFileChangeKind = z.enum(["add", "delete", "update"]);
37
+ /** Individual file change entry */
38
+ const CodexFileChangeEntry = z.object({
39
+ path: z.string(),
40
+ kind: CodexFileChangeKind,
41
+ });
42
+ /** File change item - file modifications */
43
+ const CodexFileChangeItem = z.object({
44
+ id: z.string(),
45
+ type: z.literal("file_change"),
46
+ changes: z.array(CodexFileChangeEntry),
47
+ status: z.enum(["completed", "failed"]),
48
+ });
49
+ /** Agent message item - text output from the agent */
50
+ const CodexAgentMessageItem = z.object({
51
+ id: z.string(),
52
+ type: z.literal("agent_message"),
53
+ text: z.string(),
54
+ });
55
+ /** Reasoning item - agent's reasoning process */
56
+ const CodexReasoningItem = z.object({
57
+ id: z.string(),
58
+ type: z.literal("reasoning"),
59
+ text: z.string(),
60
+ });
61
+ /** Web search item - web search query */
62
+ const CodexWebSearchItem = z.object({
63
+ id: z.string(),
64
+ type: z.literal("web_search"),
65
+ query: z.string(),
66
+ });
67
+ /** Todo item entry */
68
+ const CodexTodoEntry = z.object({
69
+ text: z.string(),
70
+ completed: z.boolean(),
71
+ });
72
+ /** Todo list item - task list */
73
+ const CodexTodoListItem = z.object({
74
+ id: z.string(),
75
+ type: z.literal("todo_list"),
76
+ items: z.array(CodexTodoEntry),
77
+ });
78
+ /** Error item - error within thread */
79
+ const CodexErrorItem = z.object({
80
+ id: z.string(),
81
+ type: z.literal("error"),
82
+ message: z.string(),
83
+ });
84
+ /** Union of all thread item types */
85
+ const CodexThreadItem = z.discriminatedUnion("type", [
86
+ CodexCommandExecutionItem,
87
+ CodexMcpToolCallItem,
88
+ CodexFileChangeItem,
89
+ CodexAgentMessageItem,
90
+ CodexReasoningItem,
91
+ CodexWebSearchItem,
92
+ CodexTodoListItem,
93
+ CodexErrorItem,
94
+ ]);
95
+ // =============================================================================
96
+ // Event Types
97
+ // =============================================================================
98
+ /** Thread started event - emitted when a new thread begins */
99
+ const CodexThreadStartedEvent = z.object({
100
+ type: z.literal("thread.started"),
101
+ thread_id: z.string(),
102
+ });
103
+ /** Turn started event - emitted when a new turn begins */
104
+ const CodexTurnStartedEvent = z.object({
105
+ type: z.literal("turn.started"),
106
+ });
107
+ /** Usage statistics for a completed turn */
108
+ const CodexUsage = z.object({
109
+ input_tokens: z.number(),
110
+ cached_input_tokens: z.number(),
111
+ output_tokens: z.number(),
112
+ });
113
+ /** Turn completed event - emitted when a turn finishes successfully */
114
+ const CodexTurnCompletedEvent = z.object({
115
+ type: z.literal("turn.completed"),
116
+ usage: CodexUsage,
117
+ });
118
+ /** Error info for failed turns */
119
+ const CodexTurnError = z.object({
120
+ message: z.string(),
121
+ });
122
+ /** Turn failed event - emitted when a turn fails */
123
+ const CodexTurnFailedEvent = z.object({
124
+ type: z.literal("turn.failed"),
125
+ error: CodexTurnError,
126
+ });
127
+ /** Item started event - emitted when an item begins processing */
128
+ const CodexItemStartedEvent = z.object({
129
+ type: z.literal("item.started"),
130
+ item: CodexThreadItem,
131
+ });
132
+ /** Item updated event - emitted when an item is updated */
133
+ const CodexItemUpdatedEvent = z.object({
134
+ type: z.literal("item.updated"),
135
+ item: CodexThreadItem,
136
+ });
137
+ /** Item completed event - emitted when an item finishes */
138
+ const CodexItemCompletedEvent = z.object({
139
+ type: z.literal("item.completed"),
140
+ item: CodexThreadItem,
141
+ });
142
+ /** Error event - top-level error */
143
+ const CodexErrorEvent = z.object({
144
+ type: z.literal("error"),
145
+ message: z.string(),
146
+ });
147
+ /** Union of all Codex CLI event types */
148
+ const CodexEvent = z.discriminatedUnion("type", [
149
+ CodexThreadStartedEvent,
150
+ CodexTurnStartedEvent,
151
+ CodexTurnCompletedEvent,
152
+ CodexTurnFailedEvent,
153
+ CodexItemStartedEvent,
154
+ CodexItemUpdatedEvent,
155
+ CodexItemCompletedEvent,
156
+ CodexErrorEvent,
157
+ ]);
158
+ // =============================================================================
159
+ // Type Guards
160
+ // =============================================================================
161
+ /** Type guard for thread.started events */
162
+ function isThreadStartedEvent(event) {
163
+ return event.type === "thread.started";
164
+ }
165
+ /** Type guard for turn.completed events */
166
+ function isTurnCompletedEvent(event) {
167
+ return event.type === "turn.completed";
168
+ }
169
+ /** Type guard for turn.failed events */
170
+ function isTurnFailedEvent(event) {
171
+ return event.type === "turn.failed";
172
+ }
173
+ /** Type guard for item.started events */
174
+ function isItemStartedEvent(event) {
175
+ return event.type === "item.started";
176
+ }
177
+ /** Type guard for item.completed events */
178
+ function isItemCompletedEvent(event) {
179
+ return event.type === "item.completed";
180
+ }
181
+ /** Type guard for error events */
182
+ function isErrorEvent(event) {
183
+ return event.type === "error";
184
+ }
185
+ // =============================================================================
186
+ // Exports
187
+ // =============================================================================
188
+ export { CodexEvent, isErrorEvent, isItemCompletedEvent, isItemStartedEvent, isThreadStartedEvent, isTurnCompletedEvent, isTurnFailedEvent, };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copilot CLI adapter implementation.
3
+ *
4
+ * Implements the {@link AgentAdapter} interface for Copilot CLI.
5
+ *
6
+ * Unlike other agents that stream JSONL to stdout, Copilot CLI writes
7
+ * session events to JSONL files in ~/.copilot/session-state/. This adapter
8
+ * uses a wrapper script that tails the session file and streams events
9
+ * to stdout.
10
+ */
11
+ export {};
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copilot CLI adapter implementation.
3
+ *
4
+ * Implements the {@link AgentAdapter} interface for Copilot CLI.
5
+ *
6
+ * Unlike other agents that stream JSONL to stdout, Copilot CLI writes
7
+ * session events to JSONL files in ~/.copilot/session-state/. This adapter
8
+ * uses a wrapper script that tails the session file and streams events
9
+ * to stdout.
10
+ */
11
+ import path from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { determineSessionSuccess } from "../../determine-session-success.js";
14
+ import { resolveBinary } from "../../resolve-binary.js";
15
+ import { registerAdapter } from "../registry.js";
16
+ import { createCopilotParser } from "./parse-event.js";
17
+ const COPILOT_INFO = {
18
+ id: "copilot",
19
+ name: "Copilot CLI",
20
+ package: "@github/copilot",
21
+ };
22
+ /** Get the path to the stream-session.js script */
23
+ function getWrapperScriptPath() {
24
+ const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
25
+ return path.join(currentDirectory, "stream-session.js");
26
+ }
27
+ /**
28
+ * Prepares the command to spawn the Copilot session streamer.
29
+ *
30
+ * Uses a wrapper script that:
31
+ * 1. Watches ~/.copilot/session-state/ for new session files
32
+ * 2. Spawns Copilot CLI with the given prompt
33
+ * 3. Tails the session JSONL file and streams events to stdout
34
+ */
35
+ function prepareCommand(options) {
36
+ const wrapperScript = getWrapperScriptPath();
37
+ // The wrapper script takes the prompt as the first argument,
38
+ // followed by any extra arguments to pass to copilot
39
+ const cliArguments = [wrapperScript, options.prompt];
40
+ // Add model flag if specified
41
+ // Copilot accepts: claude-sonnet-4.5, gpt-5, gemini-3-pro-preview, etc.
42
+ if (options.model) {
43
+ cliArguments.push("--model", options.model);
44
+ }
45
+ const environment = {};
46
+ // Pass through GitHub authentication environment variables.
47
+ // Copilot CLI checks these in priority order (highest to lowest):
48
+ // COPILOT_GITHUB_TOKEN > GH_TOKEN > GITHUB_TOKEN > GITHUB_ASKPASS
49
+ // See: copilot-cli-decompiled/copilot-source/index.js lines 216991-217011
50
+ // If not set, Copilot CLI will handle auth errors on its own.
51
+ if (process.env["COPILOT_GITHUB_TOKEN"]) {
52
+ environment["COPILOT_GITHUB_TOKEN"] = process.env["COPILOT_GITHUB_TOKEN"];
53
+ }
54
+ if (process.env["GH_TOKEN"]) {
55
+ environment["GH_TOKEN"] = process.env["GH_TOKEN"];
56
+ }
57
+ if (process.env["GITHUB_TOKEN"]) {
58
+ environment["GITHUB_TOKEN"] = process.env["GITHUB_TOKEN"];
59
+ }
60
+ const copilotBin = resolveBinary({
61
+ name: "copilot",
62
+ command: "copilot",
63
+ environmentVariable: "AXEXEC_COPILOT_PATH",
64
+ installHint: "npm install -g @github/copilot",
65
+ });
66
+ environment["AXEXEC_COPILOT_PATH"] = copilotBin;
67
+ return {
68
+ bin: process.execPath,
69
+ args: cliArguments,
70
+ env: environment,
71
+ };
72
+ }
73
+ /** Copilot CLI adapter */
74
+ const copilotAdapter = {
75
+ info: () => COPILOT_INFO,
76
+ prepareCommand,
77
+ createParser: createCopilotParser,
78
+ isSuccess: determineSessionSuccess,
79
+ };
80
+ // Self-register on import
81
+ registerAdapter(copilotAdapter);