diff --git a/cmd/server/server.go b/cmd/server/server.go index 3313b51..921ea34 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -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) diff --git a/lib/msgfmt/message_box.go b/lib/msgfmt/message_box.go index d568280..9c42468 100644 --- a/lib/msgfmt/message_box.go +++ b/lib/msgfmt/message_box.go @@ -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], "───────────────") && @@ -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") } diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index 3560aa7..1edb25e 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -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 } diff --git a/lib/msgfmt/testdata/format/codex/confirmation_box/expected.txt b/lib/msgfmt/testdata/format/codex/confirmation_box/expected.txt index 9363e91..cb2e794 100644 --- a/lib/msgfmt/testdata/format/codex/confirmation_box/expected.txt +++ b/lib/msgfmt/testdata/format/codex/confirmation_box/expected.txt @@ -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) \ No newline at end of file + 1. Allow Codex to work in this folder without asking for approval +> 2. Require approval of edits and commands + + Press Enter to continue \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/confirmation_box/msg.txt b/lib/msgfmt/testdata/format/codex/confirmation_box/msg.txt index eccfd92..cb2e794 100644 --- a/lib/msgfmt/testdata/format/codex/confirmation_box/msg.txt +++ b/lib/msgfmt/testdata/format/codex/confirmation_box/msg.txt @@ -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 \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/confirmation_box/user.txt b/lib/msgfmt/testdata/format/codex/confirmation_box/user.txt index 338205d..e69de29 100644 --- a/lib/msgfmt/testdata/format/codex/confirmation_box/user.txt +++ b/lib/msgfmt/testdata/format/codex/confirmation_box/user.txt @@ -1 +0,0 @@ -what repository are you in? \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/first_message/expected.txt b/lib/msgfmt/testdata/format/codex/first_message/expected.txt index 660ecde..6efbf6f 100644 --- a/lib/msgfmt/testdata/format/codex/first_message/expected.txt +++ b/lib/msgfmt/testdata/format/codex/first_message/expected.txt @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/first_message/msg.txt b/lib/msgfmt/testdata/format/codex/first_message/msg.txt index a779309..76b1ef4 100644 --- a/lib/msgfmt/testdata/format/codex/first_message/msg.txt +++ b/lib/msgfmt/testdata/format/codex/first_message/msg.txt @@ -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╯ \ No newline at end of file +>_ 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 \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/multi-line-input/expected.txt b/lib/msgfmt/testdata/format/codex/multi-line-input/expected.txt index a42ca83..edd162f 100644 --- a/lib/msgfmt/testdata/format/codex/multi-line-input/expected.txt +++ b/lib/msgfmt/testdata/format/codex/multi-line-input/expected.txt @@ -1,14 +1,12 @@ -command (code: 127, duration: 10ms) -$ bash -lc 'rg -n "func formatCodexMessage"' -bash: line 1: rg: command not found - -command (code: 0, duration: 8.23s) -$ bash -lc 'grep -R "formatCodexMessage" -n .' -./lib/msgfmt/testdata/format/claude/multi-line-input/user.txt:3:func formatCodexMessage(message string, userInput string) string { -./lib/msgfmt/msgfmt.go:219:func formatCodexMessage(message string, userInput string) string { -./lib/msgfmt/msgfmt.go:236: return formatCodexMessage(message, userInput) +⚡ Ran command grep -R formatCodexMessage -n . + ⎿ ./lib/msgfmt/testdata/format/codex/multi-line-input/user.txt:3:func formatCodexMessage(message string, userInput string) string {} + ./lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt:2:│$ bash -lc 'rg -n "func formatCodexMessage"' │ + ./lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt:6:│$ bash -lc 'grep -R "formatCodexMessage" -n .' │ + ... +12 lines codex -The formatCodexMessage function is defined in: +The `formatCodexMessage` function is defined in: + +`lib/msgfmt/msgfmt.go` (around line 219) -lib/msgfmt/msgfmt.go (around line 219) \ No newline at end of file + Ctrl+C again to quit 12437 tokens used 96% context left \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt b/lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt index b409343..1cee5a4 100644 --- a/lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt +++ b/lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt @@ -1,27 +1,22 @@ -│command (code: 127, duration: 10ms) │ -│$ bash -lc 'rg -n "func formatCodexMessage"' │ -│bash: line 1: rg: command not found │ -│ │ -│command (code: 0, duration: 8.23s) │ -│$ bash -lc 'grep -R "formatCodexMessage" -n .' │ -│./lib/msgfmt/testdata/format/claude/multi-line-input/user.txt:3:func formatCodexMessage(message string, userInput string) string { │ -│./lib/msgfmt/msgfmt.go:219:func formatCodexMessage(message string, userInput string) string { │ -│./lib/msgfmt/msgfmt.go:236: return formatCodexMessage(message, userInput) │ -│ │ -│codex │ -│The formatCodexMessage function is defined in: │ -│ │ -│lib/msgfmt/msgfmt.go (around line 219) │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ send a message — 97% context left │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────Enter to send | Ctrl+D to quit | Ctrl+J for newline╯ \ No newline at end of file +user +Which file has this snippet +func formatCodexMessage(message string, userInput string) string { + message = RemoveUserInput(message, userInput) + message = removeCodexInputBox(message) + message = trimEmptyLines(message) + return message +} + +⚡ Ran command grep -R formatCodexMessage -n . + ⎿ ./lib/msgfmt/testdata/format/codex/multi-line-input/user.txt:3:func formatCodexMessage(message string, userInput string) string {} + ./lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt:2:│$ bash -lc 'rg -n "func formatCodexMessage"' │ + ./lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt:6:│$ bash -lc 'grep -R "formatCodexMessage" -n .' │ + ... +12 lines + +codex +The `formatCodexMessage` function is defined in: + +`lib/msgfmt/msgfmt.go` (around line 219) + +▌ Ask Codex to do anything + Ctrl+C again to quit 12437 tokens used 96% context left \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/multi-line-input/user.txt b/lib/msgfmt/testdata/format/codex/multi-line-input/user.txt index 4250545..e85fa2a 100644 --- a/lib/msgfmt/testdata/format/codex/multi-line-input/user.txt +++ b/lib/msgfmt/testdata/format/codex/multi-line-input/user.txt @@ -1,4 +1,7 @@ -Which file is this function from? -```go -func formatCodexMessage(message string, userInput string) string {} -``` +Which file has this snippet +func formatCodexMessage(message string, userInput string) string { + message = RemoveUserInput(message, userInput) + message = removeCodexInputBox(message) + message = trimEmptyLines(message) + return message +} \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/second_message/expected.txt b/lib/msgfmt/testdata/format/codex/second_message/expected.txt index 2ce98fe..644783e 100644 --- a/lib/msgfmt/testdata/format/codex/second_message/expected.txt +++ b/lib/msgfmt/testdata/format/codex/second_message/expected.txt @@ -1,2 +1,10 @@ +⚡ Ran command git status --porcelain + ⎿ M cmd/server/server.go + M lib/msgfmt/message_box.go + M lib/msgfmt/msgfmt.go + ... +2 lines + codex -I’m doing great, thanks for asking! How can I help you today? \ No newline at end of file +There are 2 untracked files (`.env` and `forge.yaml`). + + ⏎ send Ctrl+J newline Ctrl+C quit 18724 tokens used 96% context left \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/second_message/msg.txt b/lib/msgfmt/testdata/format/codex/second_message/msg.txt index 03ece28..9e36f66 100644 --- a/lib/msgfmt/testdata/format/codex/second_message/msg.txt +++ b/lib/msgfmt/testdata/format/codex/second_message/msg.txt @@ -1,17 +1,14 @@ -│user │ -│how are you? │ -│ │ -│codex │ -│I’m doing great, thanks for asking! How can I help you today? │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ send a message — 99% context left │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────Enter to send | Ctrl+D to quit | Ctrl+J for newline╯ \ No newline at end of file +user +How many untracked files are there? + +⚡ Ran command git status --porcelain + ⎿ M cmd/server/server.go + M lib/msgfmt/message_box.go + M lib/msgfmt/msgfmt.go + ... +2 lines + +codex +There are 2 untracked files (`.env` and `forge.yaml`). + +▌ Ask Codex to do anything + ⏎ send Ctrl+J newline Ctrl+C quit 18724 tokens used 96% context left \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/second_message/user.txt b/lib/msgfmt/testdata/format/codex/second_message/user.txt index c01e0f3..f739c91 100644 --- a/lib/msgfmt/testdata/format/codex/second_message/user.txt +++ b/lib/msgfmt/testdata/format/codex/second_message/user.txt @@ -1 +1 @@ -how are you? \ No newline at end of file +How many untracked files are there? \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/thinking/expected.txt b/lib/msgfmt/testdata/format/codex/thinking/expected.txt index e69de29..856ce84 100644 --- a/lib/msgfmt/testdata/format/codex/thinking/expected.txt +++ b/lib/msgfmt/testdata/format/codex/thinking/expected.txt @@ -0,0 +1 @@ +▌ • Working (3s • Ctrl C to interrupt) \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/thinking/msg.txt b/lib/msgfmt/testdata/format/codex/thinking/msg.txt index 25fc796..521bad8 100644 --- a/lib/msgfmt/testdata/format/codex/thinking/msg.txt +++ b/lib/msgfmt/testdata/format/codex/thinking/msg.txt @@ -1,5 +1,4 @@ user -how are you? -╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│( ● ) Thinking.. │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file +Think for a very long time and tell me all about Theory of Relativity. + +▌ • Working (3s • Ctrl C to interrupt) \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/codex/thinking/user.txt b/lib/msgfmt/testdata/format/codex/thinking/user.txt index c01e0f3..8d861d0 100644 --- a/lib/msgfmt/testdata/format/codex/thinking/user.txt +++ b/lib/msgfmt/testdata/format/codex/thinking/user.txt @@ -1 +1 @@ -how are you? \ No newline at end of file +Think for a very long time and tell me all about Theory of Relativity. \ No newline at end of file