Skip to content

Commit e81a744

Browse files
authored
feat: Improved initial prompt handling (#142)
1 parent 108ad48 commit e81a744

File tree

27 files changed

+575
-0
lines changed

27 files changed

+575
-0
lines changed

lib/httpapi/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
228228
formatMessage := func(message string, userInput string) string {
229229
return mf.FormatAgentMessage(config.AgentType, message, userInput)
230230
}
231+
232+
isAgentReadyForInitialPrompt := func(message string) bool {
233+
return mf.IsAgentReadyForInitialPrompt(config.AgentType, message)
234+
}
235+
231236
conversation := st.NewConversation(ctx, st.ConversationConfig{
232237
AgentType: config.AgentType,
233238
AgentIO: config.Process,
@@ -237,6 +242,7 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
237242
SnapshotInterval: snapshotInterval,
238243
ScreenStabilityLength: 2 * time.Second,
239244
FormatMessage: formatMessage,
245+
ReadyForInitialPrompt: isAgentReadyForInitialPrompt,
240246
}, config.InitialPrompt)
241247
emitter := NewEventEmitter(1024)
242248

@@ -331,6 +337,7 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) {
331337
s.logger.Error("Failed to send initial prompt", "error", err)
332338
} else {
333339
s.conversation.InitialPromptSent = true
340+
s.conversation.ReadyForInitialPrompt = false
334341
currentStatus = st.ConversationStatusChanging
335342
s.logger.Info("Initial prompt sent successfully")
336343
}

lib/msgfmt/agent_readiness.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package msgfmt
2+
3+
func IsAgentReadyForInitialPrompt(agentType AgentType, message string) bool {
4+
switch agentType {
5+
case AgentTypeClaude:
6+
return isGenericAgentReadyForInitialPrompt(message)
7+
case AgentTypeGoose:
8+
return isGenericAgentReadyForInitialPrompt(message)
9+
case AgentTypeAider:
10+
return isGenericAgentReadyForInitialPrompt(message)
11+
case AgentTypeCodex:
12+
return isCodexAgentReadyForInitialPrompt(message)
13+
case AgentTypeGemini:
14+
return isGenericAgentReadyForInitialPrompt(message)
15+
case AgentTypeCopilot:
16+
return isGenericAgentReadyForInitialPrompt(message)
17+
case AgentTypeAmp:
18+
return isGenericAgentReadyForInitialPrompt(message)
19+
case AgentTypeCursor:
20+
return isGenericAgentReadyForInitialPrompt(message)
21+
case AgentTypeAuggie:
22+
return isGenericAgentReadyForInitialPrompt(message)
23+
case AgentTypeAmazonQ:
24+
return isGenericAgentReadyForInitialPrompt(message)
25+
case AgentTypeOpencode:
26+
return isOpencodeAgentReadyForInitialPrompt(message)
27+
case AgentTypeCustom:
28+
return isGenericAgentReadyForInitialPrompt(message)
29+
default:
30+
return true
31+
}
32+
}
33+
34+
func isGenericAgentReadyForInitialPrompt(message string) bool {
35+
message = trimEmptyLines(message)
36+
messageWithoutInputBox := removeMessageBox(message)
37+
return len(messageWithoutInputBox) != len(message)
38+
}
39+
40+
func isOpencodeAgentReadyForInitialPrompt(message string) bool {
41+
message = trimEmptyLines(message)
42+
messageWithoutInputBox := removeOpencodeMessageBox(message)
43+
return len(messageWithoutInputBox) != len(message)
44+
}
45+
46+
func isCodexAgentReadyForInitialPrompt(message string) bool {
47+
message = trimEmptyLines(message)
48+
messageWithoutInputBox := removeCodexInputBox(message)
49+
return len(messageWithoutInputBox) != len(message)
50+
}

lib/msgfmt/agent_readiness_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package msgfmt
2+
3+
import (
4+
"path"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestIsAgentReadyForInitialPrompt(t *testing.T) {
11+
dir := "testdata/initialization"
12+
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeCopilot, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeOpencode}
13+
for _, agentType := range agentTypes {
14+
t.Run(string(agentType), func(t *testing.T) {
15+
t.Run("ready", func(t *testing.T) {
16+
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "ready"))
17+
if err != nil {
18+
t.Errorf("failed to read ready cases for agent type %s: %s", agentType, err)
19+
}
20+
if len(cases) == 0 {
21+
t.Errorf("no ready cases found for agent type %s", agentType)
22+
}
23+
for _, c := range cases {
24+
if c.IsDir() {
25+
continue
26+
}
27+
t.Run(c.Name(), func(t *testing.T) {
28+
msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "ready", c.Name()))
29+
assert.NoError(t, err)
30+
assert.True(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to be ready for message:\n%s", string(msg))
31+
})
32+
}
33+
})
34+
35+
t.Run("not_ready", func(t *testing.T) {
36+
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "not_ready"))
37+
if err != nil {
38+
t.Errorf("failed to read not_ready cases for agent type %s: %s", agentType, err)
39+
}
40+
if len(cases) == 0 {
41+
t.Errorf("no not_ready cases found for agent type %s", agentType)
42+
}
43+
for _, c := range cases {
44+
if c.IsDir() {
45+
continue
46+
}
47+
t.Run(c.Name(), func(t *testing.T) {
48+
msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "not_ready", c.Name()))
49+
assert.NoError(t, err)
50+
assert.False(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to not be ready for message:\n%s", string(msg))
51+
})
52+
}
53+
})
54+
})
55+
}
56+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
────────────────────────────────────────────────────────────────────────────────
2+
Aider v0.81.1
3+
Main model: anthropic/claude-3-7-sonnet-20250219 with diff edit format, infinite
4+
output
5+
Weak model: anthropic/claude-3-5-haiku-20241022
6+
Git repo: .git with 47 files
7+
Repo-map: using 4096 tokens, auto refresh
8+
────────────────────────────────────────────────────────────────────────────────
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
────────────────────────────────────────────────────────────────────────────────
2+
Aider v0.81.1
3+
Main model: anthropic/claude-3-7-sonnet-20250219 with diff edit format, infinite
4+
output
5+
Weak model: anthropic/claude-3-5-haiku-20241022
6+
Git repo: .git with 47 files
7+
Repo-map: using 4096 tokens, auto refresh
8+
────────────────────────────────────────────────────────────────────────────────
9+
>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
✓ coder loaded in 0.03 s
2+
3+
Welcome to Amazon Q!
4+
5+
💡 Run /prompts to learn how to build & run repeatable workflows
6+
7+
/help all commands
8+
ctrl + j new lines
9+
ctrl + s fuzzy search
10+
11+
12+
🤖 You are chatting with claude-sonnet-4
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
✓ coder loaded in 0.03 s
2+
3+
Welcome to Amazon Q!
4+
5+
💡 Run /prompts to learn how to build & run repeatable workflows
6+
7+
/help all commands
8+
ctrl + j new lines
9+
ctrl + s fuzzy search
10+
11+
12+
🤖 You are chatting with claude-sonnet-4
13+
14+
>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
............
4+
..:::-------::::...
5+
..::--=========---:::... Welcome to Amp
6+
.::-===++++++++===---:::..
7+
..:--==+++******+++===--:::...
8+
.:--=+++**********++===--:::... Type / to use slash commands
9+
.::-==++***#####****++==---:::.. Type @ to mention files
10+
.:--=++****#####****++===---::... Ctrl+C to exit
11+
.:--=+++****###****+++===---:::..
12+
.:--==+++*********++++===---:::..
13+
..:--==++++*****++++====----:::.. /help for more
14+
.::--===+++++++++====-----:::...
15+
.::---===========------::::...
16+
..:::-------------:::::::... amp -x "Run the linter and fix the errors"
17+
...::::::::::::::::.....
18+
..................
19+
20+
21+
22+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
............
4+
..:::-------::::...
5+
..::--=========---:::... Welcome to Amp
6+
.::-===++++++++===---:::..
7+
..:--==+++******+++===--:::...
8+
.:--=+++**********++===--:::... Type / to use slash commands
9+
.::-==++***#####****++==---:::.. Type @ to mention files
10+
.:--=++****#####****++===---::... Ctrl+C to exit
11+
.:--=+++****###****+++===---:::..
12+
.:--==+++*********++++===---:::..
13+
..:--==++++*****++++====----:::.. /help for more
14+
.::--===+++++++++====-----:::...
15+
.::---===========------::::...
16+
..:::-------------:::::::... amp -x "Run the linter and fix the errors"
17+
...::::::::::::::::.....
18+
..................
19+
20+
21+
22+
23+
───────────────
24+
>
25+
───────────────
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
Getting started with Auggie by Augment Code
4+
1. You can ask questions, edit files, or run commands
5+
2. Your workspace is automatically indexed for best results
6+
3. Commands will run automatically
7+
8+
9+
💡 For automation, use 'auggie --print "your task"'
10+
11+
12+

0 commit comments

Comments
 (0)