Skip to content

feat: update support for codex cli #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
}
if termHeight < 10 {
return xerrors.Errorf("term height must be at least 10")
} else if agentType == AgentTypeCodex && termHeight > 930 {
logger.Warn(fmt.Sprintf("Term height is set to %d which may cause issues with Codex. Setting it to 930 instead.", termHeight))
termHeight = 930 // codex has a bug where the TUI distorts the screen if the height is too large, see: https://github.com/openai/codex/issues/1608
}

printOpenAPI := viper.GetBool(FlagPrintOpenAPI)
Expand Down
41 changes: 6 additions & 35 deletions lib/msgfmt/message_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func findGreaterThanMessageBox(lines []string) int {
// ───────────────
// |
// ───────────────
// Used by OpenAI Codex.
func findGenericSlimMessageBox(lines []string) int {
for i := len(lines) - 3; i >= max(len(lines)-9, 0); i-- {
if strings.Contains(lines[i], "───────────────") &&
Expand All @@ -52,40 +51,12 @@ func removeMessageBox(msg string) string {
return strings.Join(lines, "\n")
}

func removeCodexMessageBox(msg string) string {
func removeCodexInputBox(msg string) string {
lines := strings.Split(msg, "\n")
messageBoxEndIdx := -1
messageBoxStartIdx := -1

for i := len(lines) - 1; i >= 0; i-- {
if messageBoxEndIdx == -1 {
if strings.Contains(lines[i], "╰────────") && strings.Contains(lines[i], "───────╯") {
messageBoxEndIdx = i
}
} else {
// We reached the start of the message box (we don't want to show this line), also exit the loop
if strings.Contains(lines[i], "╭") && strings.Contains(lines[i], "───────╮") {
// We only want this to be i in case the top of the box is visible
messageBoxStartIdx = i
break
}

// We are in between the start and end of the message box, so remove the │ from the start and end of the line, let the trimEmptyLines handle the rest
if strings.HasPrefix(lines[i], "│") {
lines[i] = strings.TrimPrefix(lines[i], "│")
}
if strings.HasSuffix(lines[i], "│") {
lines[i] = strings.TrimSuffix(lines[i], "│")
lines[i] = strings.TrimRight(lines[i], " \t")
}
}
}

// If we didn't find messageBoxEndIdx, set it to the end of the lines
if messageBoxEndIdx == -1 {
messageBoxEndIdx = len(lines)
// Remove the input box, we need to match the exact pattern, because thinking follows the same pattern of ▌ followed by text
if len(lines) >= 2 && strings.Contains(lines[len(lines)-2], "▌ Ask Codex to do anything") {
idx := len(lines) - 2
lines = append(lines[:idx], lines[idx+1:]...)
}

return strings.Join(lines[messageBoxStartIdx+1:messageBoxEndIdx], "\n")

return strings.Join(lines, "\n")
}
3 changes: 1 addition & 2 deletions lib/msgfmt/msgfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ func formatGenericMessage(message string, userInput string) string {

func formatCodexMessage(message string, userInput string) string {
message = RemoveUserInput(message, userInput)
message = removeMessageBox(message)
message = removeCodexMessageBox(message)
message = removeCodexInputBox(message)
message = trimEmptyLines(message)
return message
}
Expand Down
15 changes: 7 additions & 8 deletions lib/msgfmt/testdata/format/codex/confirmation_box/expected.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Shell Command
~/Documents/work/agentapi$ git rev-parse --show-toplevel
> You are running Codex in /Users/jkmr

Allow command?
Since this folder is not version controlled, we recommend requiring
approval of all edits and commands.

▶ Yes (y)
Yes, always approve this exact command for this session (a)
Edit or give feedback (e)
No, and keep going (n)
No, and stop for now (esc)
1. Allow Codex to work in this folder without asking for approval
> 2. Require approval of edits and commands

Press Enter to continue
37 changes: 9 additions & 28 deletions lib/msgfmt/testdata/format/codex/confirmation_box/msg.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
╭Messages (tab to focus)──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│OpenAI Codex v0.10.0 (research preview) │
│ │
│codex session 790ba389-ab4d-47be-bb16-9cc7f36bcf2b │
│workdir: /Users/jkmr/Documents/work/agentapi │
│model: codex-mini-latest │
│provider: openai │
│approval: untrusted │
│sandbox: read-only │
│reasoning effort: medium │
│reasoning summaries: auto │
│ │
│user │
│what repository are you in? │
│ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭Review───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│Shell Command │
│~/Documents/work/agentapi$ git rev-parse --show-toplevel │
│ │
│Allow command? │
│ │
│ ▶ Yes (y) │
│ Yes, always approve this exact command for this session (a) │
│ Edit or give feedback (e) │
│ No, and keep going (n) │
│ No, and stop for now (esc) │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
> You are running Codex in /Users/jkmr

Since this folder is not version controlled, we recommend requiring
approval of all edits and commands.

1. Allow Codex to work in this folder without asking for approval
> 2. Require approval of edits and commands

Press Enter to continue
1 change: 0 additions & 1 deletion lib/msgfmt/testdata/format/codex/confirmation_box/user.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
what repository are you in?
18 changes: 9 additions & 9 deletions lib/msgfmt/testdata/format/codex/first_message/expected.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
OpenAI Codex v0.10.0 (research preview)
>_ You are using OpenAI Codex in ~

codex session 56576d81-529d-42f3-843b-78d870054a75
workdir: /Users/jkmr/Documents/work/agentapi
model: codex-mini-latest
provider: openai
approval: untrusted
sandbox: read-only
reasoning effort: medium
reasoning summaries: auto
To get started, describe a task or try one of these commands:

/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration and token usage
/diff - show git diff (including untracked files)
/prompts - show example prompts

⏎ send Shift+⏎ newline Ctrl+C quit
40 changes: 11 additions & 29 deletions lib/msgfmt/testdata/format/codex/first_message/msg.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
╭Messages (tab to focus)──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│OpenAI Codex v0.10.0 (research preview) │
│ │
│codex session 56576d81-529d-42f3-843b-78d870054a75 │
│workdir: /Users/jkmr/Documents/work/agentapi │
│model: codex-mini-latest │
│provider: openai │
│approval: untrusted │
│sandbox: read-only │
│reasoning effort: medium │
│reasoning summaries: auto │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ send a message │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────Enter to send | Ctrl+D to quit | Ctrl+J for newline╯
>_ You are using OpenAI Codex in ~

To get started, describe a task or try one of these commands:

/init - create an AGENTS.md file with instructions for Codex
/status - show current session configuration and token usage
/diff - show git diff (including untracked files)
/prompts - show example prompts

▌ Ask Codex to do anything
⏎ send Shift+⏎ newline Ctrl+C quit
Loading