Skip to content

Commit 702b10b

Browse files
authored
feat: update codex formatting and prevent terminal echo from being captured as agent messages (#200)
1 parent 2d98ded commit 702b10b

File tree

11 files changed

+35
-31
lines changed

11 files changed

+35
-31
lines changed

lib/msgfmt/agent_readiness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func isOpencodeAgentReadyForInitialPrompt(message string) bool {
4545

4646
func isCodexAgentReadyForInitialPrompt(message string) bool {
4747
message = trimEmptyLines(message)
48-
messageWithoutInputBox := removeCodexInputBox(message)
48+
messageWithoutInputBox := removeCodexMessageBox(message)
4949
return len(messageWithoutInputBox) != len(message)
5050
}
5151

lib/msgfmt/message_box.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ func removeMessageBox(msg string) string {
5151
return strings.Join(lines, "\n")
5252
}
5353

54-
func removeCodexInputBox(msg string) string {
54+
func removeCodexMessageBox(msg string) string {
5555
lines := strings.Split(msg, "\n")
56-
// Remove the input box, we need to match the exact pattern, because thinking follows the same pattern of ▌ followed by text
57-
if len(lines) >= 2 && strings.Contains(lines[len(lines)-2], "▌ Ask Codex to do anything") {
58-
idx := len(lines) - 2
59-
lines = append(lines[:idx], lines[idx+1:]...)
56+
if len(lines) >= 3 && strings.Contains(lines[len(lines)-3], "›") {
57+
idx := len(lines) - 3
58+
lines = append(lines[:idx], lines[idx+2])
6059
}
6160
return strings.Join(lines, "\n")
6261
}

lib/msgfmt/msgfmt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func IndexSubslice[T comparable](s, sub []T) int {
4343
// Return the runes, the lines, and the rune to line location mapping.
4444
func normalizeAndGetRuneLineMapping(msgRaw string) ([]rune, []string, []int) {
4545
msgLines := strings.Split(msgRaw, "\n")
46-
msgRuneLineLocations := []int{}
47-
runes := []rune{}
46+
var msgRuneLineLocations []int
47+
var runes []rune
4848
for lineIdx, line := range msgLines {
4949
for _, r := range line {
5050
if !strings.ContainsRune(WhiteSpaceChars, r) {
@@ -256,7 +256,7 @@ func formatGenericMessage(message string, userInput string, agentType AgentType)
256256

257257
func formatCodexMessage(message string, userInput string) string {
258258
message = RemoveUserInput(message, userInput, AgentTypeCodex)
259-
message = removeCodexInputBox(message)
259+
message = removeCodexMessageBox(message)
260260
message = trimEmptyLines(message)
261261
return message
262262
}

lib/msgfmt/testdata/format/codex/first_message/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
/diff - show git diff (including untracked files)
88
/prompts - show example prompts
99

10-
⏎ send Shift+⏎ newline Ctrl+C quit
10+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/format/codex/first_message/msg.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
/diff - show git diff (including untracked files)
88
/prompts - show example prompts
99

10-
▌ Ask Codex to do anything
11-
⏎ send Shift+⏎ newline Ctrl+C quit
10+
› A for Apple
11+
12+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/format/codex/multi-line-input/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ The `formatCodexMessage` function is defined in:
99

1010
`lib/msgfmt/msgfmt.go` (around line 219)
1111

12-
Ctrl+C again to quit 12437 tokens used 96% context left
12+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/format/codex/multi-line-input/msg.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ The `formatCodexMessage` function is defined in:
1818

1919
`lib/msgfmt/msgfmt.go` (around line 219)
2020

21-
▌ Ask Codex to do anything
22-
Ctrl+C again to quit 12437 tokens used 96% context left
21+
› Ask Codex to do anything
22+
23+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/format/codex/second_message/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
codex
88
There are 2 untracked files (`.env` and `forge.yaml`).
99

10-
⏎ send Ctrl+J newline Ctrl+C quit 18724 tokens used 96% context left
10+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/format/codex/second_message/msg.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ How many untracked files are there?
1010
codex
1111
There are 2 untracked files (`.env` and `forge.yaml`).
1212

13-
▌ Ask Codex to do anything
14-
⏎ send Ctrl+J newline Ctrl+C quit 18724 tokens used 96% context left
13+
› Ask Codex to do anything
14+
15+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

lib/msgfmt/testdata/initialization/codex/ready/msg.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
/diff - show git diff (including untracked files)
88
/prompts - show example prompts
99

10-
▌ Ask Codex to do anything
11-
⏎ send Shift+⏎ newline Ctrl+C quit
10+
› Refactor this Code...
11+
12+
gpt-5.1-codex-max default · 100% left · ~/Documents/work/coder_o…

0 commit comments

Comments
 (0)