Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
12 changes: 9 additions & 3 deletions lib/httpapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,21 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
formatMessage := func(message string, userInput string) string {
return mf.FormatAgentMessage(config.AgentType, message, userInput)
}

isAgentReadyForInitialPrompt := func(message string) bool {
return mf.IsAgentReadyForInitialPrompt(config.AgentType, message)
}

conversation := st.NewConversation(ctx, st.ConversationConfig{
AgentType: config.AgentType,
AgentIO: config.Process,
GetTime: func() time.Time {
return time.Now()
},
SnapshotInterval: snapshotInterval,
ScreenStabilityLength: 2 * time.Second,
FormatMessage: formatMessage,
SnapshotInterval: snapshotInterval,
ScreenStabilityLength: 2 * time.Second,
FormatMessage: formatMessage,
IsAgentReadyForInitialPrompt: isAgentReadyForInitialPrompt,
}, config.InitialPrompt)
emitter := NewEventEmitter(1024)

Expand Down
50 changes: 50 additions & 0 deletions lib/msgfmt/agent_readiness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package msgfmt

func IsAgentReadyForInitialPrompt(agentType AgentType, message string) bool {
switch agentType {
case AgentTypeClaude:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeGoose:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeAider:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeCodex:
return isCodexAgentReadyForInitialPrompt(message)
case AgentTypeGemini:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeCopilot:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeAmp:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeCursor:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeAuggie:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeAmazonQ:
return isGenericAgentReadyForInitialPrompt(message)
case AgentTypeOpencode:
return isOpencodeAgentReadyForInitialPrompt(message)
case AgentTypeCustom:
return isGenericAgentReadyForInitialPrompt(message)
default:
return true
}
}

func isGenericAgentReadyForInitialPrompt(message string) bool {
message = trimEmptyLines(message)
messageWithoutInputBox := removeMessageBox(message)
return len(messageWithoutInputBox) != len(message)
}

func isOpencodeAgentReadyForInitialPrompt(message string) bool {
message = trimEmptyLines(message)
messageWithoutInputBox := removeOpencodeMessageBox(message)
return len(messageWithoutInputBox) != len(message)
}

func isCodexAgentReadyForInitialPrompt(message string) bool {
message = trimEmptyLines(message)
messageWithoutInputBox := removeCodexInputBox(message)
return len(messageWithoutInputBox) != len(message)
}
56 changes: 56 additions & 0 deletions lib/msgfmt/agent_readiness_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package msgfmt

import (
"path"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsAgentReadyForInitialPrompt(t *testing.T) {
dir := "testdata/initialization"
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeCopilot, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeOpencode, AgentTypeCustom}
for _, agentType := range agentTypes {
t.Run(string(agentType), func(t *testing.T) {
t.Run("ready", func(t *testing.T) {
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "ready"))
if err != nil {
t.Skipf("failed to read ready cases for agent type %s: %s", agentType, err)
}
if len(cases) == 0 {
t.Skipf("no ready cases found for agent type %s", agentType)
}
for _, c := range cases {
if c.IsDir() {
continue
}
t.Run(c.Name(), func(t *testing.T) {
msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "ready", c.Name()))
assert.NoError(t, err)
assert.True(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to be ready for message:\n%s", string(msg))
})
}
})

t.Run("not_ready", func(t *testing.T) {
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType), "not_ready"))
if err != nil {
t.Skipf("failed to read not_ready cases for agent type %s: %s", agentType, err)
}
if len(cases) == 0 {
t.Skipf("no not_ready cases found for agent type %s", agentType)
}
for _, c := range cases {
if c.IsDir() {
continue
}
t.Run(c.Name(), func(t *testing.T) {
msg, err := testdataDir.ReadFile(path.Join(dir, string(agentType), "not_ready", c.Name()))
assert.NoError(t, err)
assert.False(t, IsAgentReadyForInitialPrompt(agentType, string(msg)), "Expected agent to not be ready for message:\n%s", string(msg))
})
}
})
})
}
}
8 changes: 8 additions & 0 deletions lib/msgfmt/testdata/initialization/aider/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
────────────────────────────────────────────────────────────────────────────────
Aider v0.81.1
Main model: anthropic/claude-3-7-sonnet-20250219 with diff edit format, infinite
output
Weak model: anthropic/claude-3-5-haiku-20241022
Git repo: .git with 47 files
Repo-map: using 4096 tokens, auto refresh
────────────────────────────────────────────────────────────────────────────────
9 changes: 9 additions & 0 deletions lib/msgfmt/testdata/initialization/aider/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
────────────────────────────────────────────────────────────────────────────────
Aider v0.81.1
Main model: anthropic/claude-3-7-sonnet-20250219 with diff edit format, infinite
output
Weak model: anthropic/claude-3-5-haiku-20241022
Git repo: .git with 47 files
Repo-map: using 4096 tokens, auto refresh
────────────────────────────────────────────────────────────────────────────────
>
12 changes: 12 additions & 0 deletions lib/msgfmt/testdata/initialization/amazonq/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
✓ coder loaded in 0.03 s

Welcome to Amazon Q!

💡 Run /prompts to learn how to build & run repeatable workflows

/help all commands
ctrl + j new lines
ctrl + s fuzzy search


🤖 You are chatting with claude-sonnet-4
14 changes: 14 additions & 0 deletions lib/msgfmt/testdata/initialization/amazonq/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
✓ coder loaded in 0.03 s

Welcome to Amazon Q!

💡 Run /prompts to learn how to build & run repeatable workflows

/help all commands
ctrl + j new lines
ctrl + s fuzzy search


🤖 You are chatting with claude-sonnet-4

>
22 changes: 22 additions & 0 deletions lib/msgfmt/testdata/initialization/amp/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


............
..:::-------::::...
..::--=========---:::... Welcome to Amp
.::-===++++++++===---:::..
..:--==+++******+++===--:::...
.:--=+++**********++===--:::... Type / to use slash commands
.::-==++***#####****++==---:::.. Type @ to mention files
.:--=++****#####****++===---::... Ctrl+C to exit
.:--=+++****###****+++===---:::..
.:--==+++*********++++===---:::..
..:--==++++*****++++====----:::.. /help for more
.::--===+++++++++====-----:::...
.::---===========------::::...
..:::-------------:::::::... amp -x "Run the linter and fix the errors"
...::::::::::::::::.....
..................




25 changes: 25 additions & 0 deletions lib/msgfmt/testdata/initialization/amp/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


............
..:::-------::::...
..::--=========---:::... Welcome to Amp
.::-===++++++++===---:::..
..:--==+++******+++===--:::...
.:--=+++**********++===--:::... Type / to use slash commands
.::-==++***#####****++==---:::.. Type @ to mention files
.:--=++****#####****++===---::... Ctrl+C to exit
.:--=+++****###****+++===---:::..
.:--==+++*********++++===---:::..
..:--==++++*****++++====----:::.. /help for more
.::--===+++++++++====-----:::...
.::---===========------::::...
..:::-------------:::::::... amp -x "Run the linter and fix the errors"
...::::::::::::::::.....
..................




───────────────
>
───────────────
12 changes: 12 additions & 0 deletions lib/msgfmt/testdata/initialization/auggie/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


Getting started with Auggie by Augment Code
1. You can ask questions, edit files, or run commands
2. Your workspace is automatically indexed for best results
3. Commands will run automatically


💡 For automation, use 'auggie --print "your task"'



19 changes: 19 additions & 0 deletions lib/msgfmt/testdata/initialization/auggie/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


Getting started with Auggie by Augment Code
1. You can ask questions, edit files, or run commands
2. Your workspace is automatically indexed for best results
3. Commands will run automatically


💡 For automation, use 'auggie --print "your task"'




╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ › Try 'how do I log an error?' or type / for commands │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Type / for commands • ↑↓ for history • Esc/Ctrl+C to interrupt ~/Documents/work/agentapi


14 changes: 14 additions & 0 deletions lib/msgfmt/testdata/initialization/claude/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
╭────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview! │
│ │
│ /help for help │
│ │
│ cwd: /Users/hugodutka/dev/agentapi │
╰────────────────────────────────────────────╯

Tips for getting started:

1. Run /init to create a CLAUDE.md file with instructions for Claude
2. Run /terminal-setup to set up terminal integration
3. Use Claude to help with file analysis, editing, bash commands and git
4. Be as specific as you would with another engineer for the best results
19 changes: 19 additions & 0 deletions lib/msgfmt/testdata/initialization/claude/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
╭────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview! │
│ │
│ /help for help │
│ │
│ cwd: /Users/hugodutka/dev/agentapi │
╰────────────────────────────────────────────╯

Tips for getting started:

1. Run /init to create a CLAUDE.md file with instructions for Claude
2. Run /terminal-setup to set up terminal integration
3. Use Claude to help with file analysis, editing, bash commands and git
4. Be as specific as you would with another engineer for the best results

╭──────────────────────────────────────────────────────────────────────────────╮
│ > Try "refactor handler.go" │
╰──────────────────────────────────────────────────────────────────────────────╯
? for shortcuts
8 changes: 8 additions & 0 deletions lib/msgfmt/testdata/initialization/codex/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
>_ 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
11 changes: 11 additions & 0 deletions lib/msgfmt/testdata/initialization/codex/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
>_ 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
11 changes: 11 additions & 0 deletions lib/msgfmt/testdata/initialization/copilot/not_ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Welcome to GitHub Copilot CLI
Version 0.0.328 · Commit 3755a93

Copilot can write, test and debug code right from your terminal. Describe a
task to get started or enter ? for help. Copilot uses AI, check for mistakes.

● Logged in with gh as user: 35C4n0r

● Connected to GitHub MCP Server

~/Documents/work/agentapi [⎇ feat-github-cli*]
15 changes: 15 additions & 0 deletions lib/msgfmt/testdata/initialization/copilot/ready/msg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Welcome to GitHub Copilot CLI
Version 0.0.328 · Commit 3755a93

Copilot can write, test and debug code right from your terminal. Describe a
task to get started or enter ? for help. Copilot uses AI, check for mistakes.

● Logged in with gh as user: 35C4n0r

● Connected to GitHub MCP Server

~/Documents/work/agentapi [⎇ feat-github-cli*]
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Enter @ to mention files or / for commands │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Ctrl+c Exit · Ctrl+r Expand all
Loading