-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodexClient.java
More file actions
1211 lines (1086 loc) · 43.9 KB
/
Copy pathCodexClient.java
File metadata and controls
1211 lines (1086 loc) · 43.9 KB
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2018-present, easy-4-java (https://github.com/easy-4-java).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.easy4j.codex;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import io.github.easy4j.codex.cli.CodexCli;
import io.github.easy4j.codex.cli.CodexCliExecutor;
import io.github.easy4j.codex.cli.CodexCliResult;
import io.github.easy4j.codex.model.CodexDoctorReport;
import io.github.easy4j.codex.model.CodexEvent;
import io.github.easy4j.codex.model.CodexSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* High-level Java facade that wraps every local {@code codex} CLI invocation
* behind ergonomic, strongly-typed methods.
*
* <p>This class is the recommended entry point for application code. It owns
* a single {@link CodexClientConfig} and a single {@link CodexCli}, forwarding
* the configured defaults to every call so that callers only need to supply
* the call-specific overrides (e.g. the prompt or output file).</p>
*
* <h3>Session management</h3>
* <p>Codex persists sessions as files under {@code ~/.codex/} and exposes
* session lifecycle through the {@code resume} / {@code fork} / {@code archive}
* sub-commands. This SDK models each of those sub-commands as a Java method
* so application code does not have to reason about CLI spelling.</p>
*
* <h3>JSON-Lines parsing</h3>
* <p>{@link #execAndParse(String)} runs {@code codex exec --json <prompt>} and
* decodes the standard output into a {@code List<CodexEvent>} using a private
* Jackson {@link ObjectMapper} that ignores unknown properties.</p>
*
* @author <a href="https://github.com/loong10k">Loong Wan</a>
* @since 3.0.0
* @see CodexClientConfig
* @see CodexCli
* @see CodexCliResult
*/
public class CodexClient implements AutoCloseable {
private static final Logger log = LoggerFactory.getLogger(CodexClient.class);
private static final ObjectMapper MAPPER = JsonMapper.builder().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
private final CodexClientConfig config;
private final CodexCli cli;
/**
* Creates a new client backed by the given configuration. A default
* {@link CodexCli} and {@link CodexCliExecutor} are constructed
* automatically.
*
* @param config runtime configuration; must not be {@code null}.
* @throws NullPointerException if {@code config} is {@code null}.
*/
public CodexClient(CodexClientConfig config) {
this.config = Objects.requireNonNull(config, "config");
this.cli = new CodexCli(new CodexCliExecutor(config));
}
/**
* Creates a new client that delegates to the supplied {@link CodexCli}.
*
* <p>This constructor exists primarily for testing — it lets a
* caller substitute a {@link CodexCli} backed by a mocked executor while
* still using the default behaviour of the surrounding facade.</p>
*
* @param config runtime configuration; must not be {@code null}.
* @param cli the CLI facade to delegate to; must not be {@code null}.
* @throws NullPointerException if either argument is {@code null}.
*/
public CodexClient(CodexClientConfig config, CodexCli cli) {
this.config = Objects.requireNonNull(config, "config");
this.cli = Objects.requireNonNull(cli, "cli");
}
// ============================================================
// Basic info
// ============================================================
/**
* Runs {@code codex --version}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult version() { return cli.version(); }
/**
* Runs {@code codex --help}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult help() { return cli.help(); }
// ============================================================
// exec — non-interactive execution
// ============================================================
/**
* Sends {@code prompt} and blocks until the {@code codex exec} call
* returns, propagating every default from the client configuration.
*
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult exec(String prompt) {
CodexCli.ExecOptions opts = defaultOptions(prompt);
return cli.executor().execute(opts.toArgs());
}
/**
* Sends {@code prompt} using the specified {@code model} and enables
* {@code --json} output so the result can be parsed into events.
*
* @param prompt the prompt to feed to the agent.
* @param model the model identifier to pin for this call.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult exec(String prompt, String model) {
return cli.exec(new CodexCli.ExecOptions(prompt).model(model).json(true));
}
/**
* Runs {@code codex exec} with the supplied, fully-configured options.
*
* @param opts execution options; must not be {@code null}.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult exec(CodexCli.ExecOptions opts) {
return cli.executor().execute(opts.toArgs());
}
/**
* Convenience wrapper that runs {@code exec(prompt)} and decodes the
* standard output into a list of {@link CodexEvent} instances.
*
* @param prompt the prompt to feed to the agent.
* @return the parsed JSON-Lines events; an empty list when the output is
* empty or unparseable.
*/
public List<CodexEvent> execAndParse(String prompt) {
CodexCli.ExecOptions opts = defaultOptions(prompt).json(true);
CodexCliResult result = cli.exec(opts);
return parseJsonlOutput(result.getStdout());
}
/**
* Runs {@code codex exec} with the {@code -C} flag pointed at the given
* directory.
*
* @param workingDir the working directory passed via {@code -C}.
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execInDir(String workingDir, String prompt) {
return cli.exec(new CodexCli.ExecOptions(prompt).workingDir(workingDir));
}
/**
* Runs {@code codex exec --ephemeral <prompt>} — the session is not
* persisted to disk after the call completes.
*
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execEphemeral(String prompt) {
return cli.exec(new CodexCli.ExecOptions(prompt).ephemeral(true));
}
/**
* Runs {@code codex exec --search <prompt>} so the agent can call the
* web-search tool during execution.
*
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithSearch(String prompt) {
return cli.exec(new CodexCli.ExecOptions(prompt).search(true));
}
/**
* Runs {@code codex exec -o <outputFile> <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @param outputFile destination file for the final message.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execToFile(String prompt, String outputFile) {
return cli.exec(new CodexCli.ExecOptions(prompt).outputFile(outputFile));
}
/**
* Runs {@code codex exec --output-schema <schema> <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @param outputSchema JSON Schema path describing the expected structured output.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithSchema(String prompt, String outputSchema) {
return cli.exec(new CodexCli.ExecOptions(prompt).outputSchema(outputSchema));
}
/**
* Runs {@code codex exec --image <imagePath> <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @param imagePath path to an image attachment forwarded to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithImage(String prompt, String imagePath) {
return cli.exec(new CodexCli.ExecOptions(prompt).image(imagePath));
}
/**
* Runs {@code codex exec} with one or more {@code -c key=value} overrides.
*
* @param prompt the prompt to feed to the agent.
* @param configOverrides each element becomes a separate {@code -c} flag.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithConfigOverrides(String prompt, String... configOverrides) {
return cli.exec(new CodexCli.ExecOptions(prompt).configOverrides(configOverrides));
}
/**
* Runs {@code codex exec --dangerously-bypass-approvals-and-sandbox
* <prompt>}. <strong>Use with extreme caution</strong>.
*
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execDangerously(String prompt) {
return cli.exec(new CodexCli.ExecOptions(prompt).dangerouslyBypassApprovalsAndSandbox(true));
}
/**
* Runs {@code codex exec --dangerously-bypass-hook-trust <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execBypassHookTrust(String prompt) {
return cli.exec(new CodexCli.ExecOptions(prompt).dangerouslyBypassHookTrust(true));
}
/**
* Runs {@code codex exec --enable <feature>... <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @param features feature flags to enable.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithEnable(String prompt, String... features) {
return cli.exec(new CodexCli.ExecOptions(prompt).enable(features));
}
/**
* Runs {@code codex exec --disable <feature>... <prompt>}.
*
* @param prompt the prompt to feed to the agent.
* @param features feature flags to disable.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execWithDisable(String prompt, String... features) {
return cli.exec(new CodexCli.ExecOptions(prompt).disable(features));
}
// ============================================================
// Interactive session
// ============================================================
/**
* Starts an interactive session with no initial prompt.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult startSession() {
return cli.startInteractive(defaultGlobalOptions(), null);
}
/**
* Starts an interactive session seeded with the given prompt.
*
* @param prompt the opening prompt; may be {@code null}.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult startSession(String prompt) {
return cli.startInteractive(defaultGlobalOptions(), prompt);
}
/**
* Starts an interactive session configured with the supplied global
* options and seeded with the given prompt.
*
* @param opts the global options to apply before the prompt.
* @param prompt the opening prompt; may be {@code null}.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult startSession(CodexCli.GlobalOptions opts, String prompt) {
return cli.startInteractive(opts, prompt);
}
// ============================================================
// exec resume — resuming non-interactive sessions
// ============================================================
/**
* Resumes the named session and appends the supplied prompt.
*
* @param sessionId the session identifier to resume.
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execResume(String sessionId, String prompt) {
return cli.execResume(sessionId, prompt);
}
/**
* Resumes the most recent non-interactive session and appends the
* supplied prompt.
*
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execResumeLast(String prompt) {
return cli.execResumeLast(prompt);
}
/**
* Resumes the most recent session without appending any prompt.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execResumeLast() {
return cli.execResumeLast();
}
/**
* Resumes the most recent session, appends the supplied prompt, and
* writes the final message to {@code outputFile}.
*
* @param prompt the prompt to append.
* @param outputFile destination file for the final message.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execResumeLastToFile(String prompt, String outputFile) {
return cli.execResumeLast(prompt, outputFile);
}
/**
* Resumes the named session together with its entire history and appends
* the supplied prompt.
*
* @param sessionId the session identifier to resume.
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult execResumeAll(String sessionId, String prompt) {
return cli.execResumeAll(sessionId, prompt);
}
// ============================================================
// review — code review
// ============================================================
/**
* Runs {@code codex review}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult review() { return cli.review(); }
/**
* Runs {@code codex review --uncommitted}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult reviewUncommitted() { return cli.reviewUncommitted(); }
/**
* Runs {@code codex review --base <branch>}.
*
* @param branch the branch used as the review baseline.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult reviewBase(String branch) { return cli.reviewBase(branch); }
/**
* Runs {@code codex review --commit <sha>}.
*
* @param sha the commit SHA used as the review baseline.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult reviewCommit(String sha) { return cli.reviewCommit(sha); }
/**
* Runs {@code codex review --title <title> <prompt>}.
*
* @param prompt the review prompt.
* @param title the human-readable review title.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult review(String prompt, String title) {
return cli.review(prompt, title);
}
// ============================================================
// Session lifecycle
// ============================================================
/**
* Resumes an interactive session by id.
*
* @param sessionId the session identifier to resume.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeSession(String sessionId) {
return cli.resume(sessionId);
}
/**
* Resumes an interactive session by id and appends the supplied prompt.
*
* @param sessionId the session identifier to resume.
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeSession(String sessionId, String prompt) {
return cli.resume(sessionId, prompt);
}
/**
* Resumes the most recent interactive session.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeLastSession() {
return cli.resumeLast();
}
/**
* Resumes the most recent interactive session and appends the supplied
* prompt.
*
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeLastSession(String prompt) {
return cli.resumeLast(prompt);
}
/**
* Lists every session across all directories.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeAllSessions() {
return cli.resumeAll();
}
/**
* Resumes the most recent session, including non-interactive ones.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult resumeIncludeNonInteractive() {
return cli.resumeIncludeNonInteractive();
}
/**
* Forks the named session.
*
* @param sessionId the session identifier to fork.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult forkSession(String sessionId) {
return cli.fork(sessionId);
}
/**
* Forks the named session and appends the supplied prompt.
*
* @param sessionId the session identifier to fork.
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult forkSession(String sessionId, String prompt) {
return cli.fork(sessionId, prompt);
}
/**
* Forks the most recent session.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult forkLastSession() {
return cli.forkLast();
}
/**
* Forks the most recent session and appends the supplied prompt.
*
* @param prompt the prompt to append.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult forkLastSession(String prompt) {
return cli.forkLast(prompt);
}
/**
* Forks the named session, scanning the entire session index.
*
* @param sessionId the session identifier to fork.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult forkAllSessions(String sessionId) {
return cli.forkAll(sessionId);
}
/**
* Archives the named session.
*
* @param sessionId the session identifier to archive.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult archiveSession(String sessionId) {
return cli.archive(sessionId);
}
/**
* Unarchives the named session.
*
* @param sessionId the session identifier to unarchive.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult unarchiveSession(String sessionId) {
return cli.unarchive(sessionId);
}
// ============================================================
// apply
// ============================================================
/**
* Applies the diff produced by the given task to the working tree.
*
* @param taskId the task identifier.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult apply(String taskId) {
return cli.apply(taskId);
}
// ============================================================
// queue / delete / agents / migrate-rollouts
// ============================================================
/**
* Queues {@code message} for an existing session via
* {@code codex queue --thread <thread> --message <message>}.
*
* @param thread the session UUID or exact session name.
* @param message the message text to queue.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult queue(String thread, String message) { return cli.queue(thread, message); }
/**
* Permanently deletes a saved session via {@code codex delete <session>}.
* The CLI prompts for confirmation on a TTY; prefer
* {@link #deleteSessionForce(String)} for non-interactive use.
*
* @param session the session UUID or session name.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult deleteSession(String session) { return cli.delete(session); }
/**
* Permanently deletes a session without prompting via
* {@code codex delete --force <session>}. Requires a session UUID.
*
* @param sessionUuid the session UUID.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult deleteSessionForce(String sessionUuid) { return cli.deleteForce(sessionUuid); }
/**
* Browses agent sessions on the shared local app-server daemon via
* {@code codex agents <args...>}.
*
* @param args optional extra arguments.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult agents(String... args) { return cli.agents(args); }
/**
* Inspects or migrates legacy local sessions via
* {@code codex migrate-rollouts <args...>}.
*
* @param args optional extra arguments.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult migrateRollouts(String... args) { return cli.migrateRollouts(args); }
// ============================================================
// auth
// ============================================================
/**
* Runs {@code codex login}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult login() { return cli.login(); }
/**
* Logs in headlessly with an API key via
* {@code codex login --with-api-key} (key piped to stdin).
*
* @param apiKey the API key.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult loginWithApiKey(String apiKey) { return cli.loginWithApiKey(apiKey); }
/**
* Logs in with an access token via
* {@code codex login --with-access-token} (token piped to stdin).
*
* @param accessToken the access token.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult loginWithAccessToken(String accessToken) { return cli.loginWithAccessToken(accessToken); }
/**
* Starts the OAuth device-code login flow via
* {@code codex login --device-auth}; the verification URL and device code
* are printed on stdout.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult loginDeviceAuth() { return cli.loginDeviceAuth(); }
/**
* Prints the current auth mode via {@code codex login status}; the CLI
* exits {@code 0} when logged in.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult loginStatus() { return cli.loginStatus(); }
/**
* Runs {@code codex logout}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult logout() { return cli.logout(); }
// ============================================================
// mcp
// ============================================================
/**
* Runs {@code codex mcp list}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpList() { return cli.mcpList(); }
/**
* Runs {@code codex mcp get <name>}.
*
* @param name the MCP server name.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpGet(String name) { return cli.mcpGet(name); }
/**
* Runs {@code codex mcp add <name> <command> [args...]}.
*
* @param name the MCP server name.
* @param command the launcher command.
* @param args optional extra arguments.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpAdd(String name, String command, String... args) { return cli.mcpAdd(name, command, args); }
/**
* Runs {@code codex mcp remove <name>}.
*
* @param name the MCP server name.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpRemove(String name) { return cli.mcpRemove(name); }
/**
* Runs {@code codex mcp login <name>}.
*
* @param name the MCP server name.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpLogin(String name) { return cli.mcpLogin(name); }
/**
* Runs {@code codex mcp logout <name>}.
*
* @param name the MCP server name.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult mcpLogout(String name) { return cli.mcpLogout(name); }
// ============================================================
// doctor
// ============================================================
/**
* Runs {@code codex doctor}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult doctor() { return cli.doctor(); }
/**
* Runs {@code codex doctor --json}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult doctorJson() { return cli.doctorJson(); }
/**
* Runs {@code codex doctor --summary}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult doctorSummary() { return cli.doctorSummary(); }
// ============================================================
// Other commands
// ============================================================
/**
* Runs {@code codex update}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult update() { return cli.update(); }
/**
* Runs {@code codex completion <shell>}.
*
* @param shell the target shell name.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult completion(String shell) { return cli.completion(shell); }
/**
* Runs {@code codex features}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult features() { return cli.features(); }
/**
* Runs {@code codex debug models} — the raw model catalog as JSON.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult debugModels() { return cli.debugModels(); }
/**
* Runs {@code codex debug models --bundled} — only the bundled catalog.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult debugModelsBundled() { return cli.debugModelsBundled(); }
/**
* Runs {@code codex debug prompt-input <prompt>} — the model-visible
* prompt input list as JSON.
*
* @param prompt the prompt to render.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult debugPromptInput(String prompt) { return cli.debugPromptInput(prompt); }
/**
* Runs {@code codex mcp add <name> --url <url>} — registers a streamable
* HTTP MCP server.
*
* @param name the MCP server name.
* @param url the streamable HTTP endpoint URL.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult mcpAddUrl(String name, String url) { return cli.mcpAddUrl(name, url); }
/**
* Runs {@code codex mcp add <name> --url <url> --bearer-token-env-var <env>}
* — registers an HTTP MCP server whose bearer token lives in an env var.
*
* @param name the MCP server name.
* @param url the streamable HTTP endpoint URL.
* @param bearerTokenEnvVar environment variable holding the bearer token.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult mcpAddUrlWithBearer(String name, String url, String bearerTokenEnvVar) {
return cli.mcpAddUrlWithBearer(name, url, bearerTokenEnvVar);
}
/**
* Runs {@code codex plugin add <plugin[@marketplace]>}.
*
* @param pluginRef plugin reference.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginAdd(String pluginRef) { return cli.pluginAdd(pluginRef); }
/**
* Runs {@code codex plugin list}.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginList() { return cli.pluginList(); }
/**
* Runs {@code codex plugin remove <plugin[@marketplace]>}.
*
* @param pluginRef plugin reference to remove.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginRemove(String pluginRef) { return cli.pluginRemove(pluginRef); }
/**
* Runs {@code codex plugin marketplace add <source>}.
*
* @param source the marketplace source.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginMarketplaceAdd(String source) { return cli.pluginMarketplaceAdd(source); }
/**
* Runs {@code codex plugin marketplace list}.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginMarketplaceList() { return cli.pluginMarketplaceList(); }
/**
* Runs {@code codex plugin marketplace remove <name>}.
*
* @param name the marketplace name.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginMarketplaceRemove(String name) { return cli.pluginMarketplaceRemove(name); }
/**
* Runs {@code codex plugin marketplace upgrade <name>}.
*
* @param name the marketplace name to upgrade.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult pluginMarketplaceUpgrade(String name) { return cli.pluginMarketplaceUpgrade(name); }
/**
* Runs {@code codex cloud exec --env <envId> <query>} — submits a cloud task.
*
* @param envId the cloud environment id.
* @param query the task query.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult cloudExec(String envId, String query) { return cli.cloudExec(envId, query); }
/**
* Runs {@code codex cloud list --env <envId> --json}.
*
* @param envId the cloud environment id.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult cloudList(String envId) { return cli.cloudList(envId); }
/**
* Runs {@code codex features enable <feature>}.
*
* @param feature the feature flag name.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult featuresEnable(String feature) { return cli.featuresEnable(feature); }
/**
* Runs {@code codex features disable <feature>}.
*
* @param feature the feature flag name.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult featuresDisable(String feature) { return cli.featuresDisable(feature); }
/**
* Runs {@code codex features list}.
*
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult featuresList() { return cli.featuresList(); }
/**
* Runs {@code codex review <prompt>} — a custom-instruction review.
*
* @param prompt the review instruction.
* @return the raw CLI invocation result; never {@code null}.
* @since 3.0.0
*/
public CodexCliResult reviewPrompt(String prompt) { return cli.reviewPrompt(prompt); }
/**
* Runs {@code codex mcp-server}.
*
* <p><strong>Deprecated:</strong> the subcommand has been removed from
* recent Codex CLI releases — use {@link #appServer(String...)}.
* Kept for callers pinned to older CLI builds.</p>
*
* @return the raw CLI invocation result; never {@code null}.
* @deprecated upstream removed {@code codex mcp-server}; use {@link #appServer(String...)}.
*/
@Deprecated
public CodexCliResult mcpServer() { return cli.mcpServer(); }
/**
* Runs {@code codex app}.
*
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult app() { return cli.app(); }
/**
* Runs {@code codex sandbox <command...>}.
*
* @param command the shell command to execute inside the sandbox.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult sandbox(String... command) { return cli.sandbox(command); }
/**
* Runs {@code codex sandbox --permission-profile <profile> <command...>}.
*
* @param profile the permissions profile name.
* @param command the shell command to execute inside the sandbox.
* @return the raw CLI invocation result; never {@code null}.
*/
public CodexCliResult sandbox(String profile, String... command) { return cli.sandbox(profile, command); }
/**
* Runs {@code codex debug <args...>}.
*
* @param args arguments forwarded to the debug sub-command.
* @return the raw CLI invocation result; never {@code null}.