Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
62 changes: 29 additions & 33 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,44 @@ import (
type AgentType = msgfmt.AgentType

const (
AgentTypeClaude AgentType = msgfmt.AgentTypeClaude
AgentTypeGoose AgentType = msgfmt.AgentTypeGoose
AgentTypeAider AgentType = msgfmt.AgentTypeAider
AgentTypeCodex AgentType = msgfmt.AgentTypeCodex
AgentTypeGemini AgentType = msgfmt.AgentTypeGemini
AgentTypeAmp AgentType = msgfmt.AgentTypeAmp
AgentTypeCursorAgent AgentType = msgfmt.AgentTypeCursorAgent
AgentTypeCursor AgentType = msgfmt.AgentTypeCursor
AgentTypeAuggie AgentType = msgfmt.AgentTypeAuggie
AgentTypeAmazonQ AgentType = msgfmt.AgentTypeAmazonQ
AgentTypeQ AgentType = msgfmt.AgentTypeQ
AgentTypeCustom AgentType = msgfmt.AgentTypeCustom
AgentTypeClaude AgentType = msgfmt.AgentTypeClaude
AgentTypeGoose AgentType = msgfmt.AgentTypeGoose
AgentTypeAider AgentType = msgfmt.AgentTypeAider
AgentTypeCodex AgentType = msgfmt.AgentTypeCodex
AgentTypeGemini AgentType = msgfmt.AgentTypeGemini
AgentTypeAmp AgentType = msgfmt.AgentTypeAmp
AgentTypeCursor AgentType = msgfmt.AgentTypeCursor
AgentTypeAuggie AgentType = msgfmt.AgentTypeAuggie
AgentTypeAmazonQ AgentType = msgfmt.AgentTypeAmazonQ
AgentTypeCustom AgentType = msgfmt.AgentTypeCustom
)

// exhaustiveness of this map is checked by the exhaustive linter
var agentTypeMap = map[AgentType]bool{
AgentTypeClaude: true,
AgentTypeGoose: true,
AgentTypeAider: true,
AgentTypeCodex: true,
AgentTypeGemini: true,
AgentTypeAmp: true,
AgentTypeCursorAgent: true,
AgentTypeCursor: true,
AgentTypeAuggie: true,
AgentTypeAmazonQ: true,
AgentTypeQ: true,
AgentTypeCustom: true,
// agentTypeAliases contains the mapping of possible input agent type strings to their canonical AgentType values
var agentTypeAliases = map[string]AgentType{
"claude": AgentTypeClaude,
"goose": AgentTypeGoose,
"aider": AgentTypeAider,
"codex": AgentTypeCodex,
"gemini": AgentTypeGemini,
"amp": AgentTypeAmp,
"auggie": AgentTypeAuggie,
"cursor": AgentTypeCursor,
"cursor-agent": AgentTypeCursor,
"q": AgentTypeAmazonQ,
"amazonq": AgentTypeAmazonQ,
"custom": AgentTypeCustom,
}

func parseAgentType(firstArg string, agentTypeVar string) (AgentType, error) {
// if the agent type is provided, use it
castedAgentType := AgentType(agentTypeVar)
if _, ok := agentTypeMap[castedAgentType]; ok {
if castedAgentType, ok := agentTypeAliases[agentTypeVar]; ok {
return castedAgentType, nil
}
if agentTypeVar != "" {
return AgentTypeCustom, fmt.Errorf("invalid agent type: %s", agentTypeVar)
}
// if the agent type is not provided, guess it from the first argument
castedFirstArg := AgentType(firstArg)
if _, ok := agentTypeMap[castedFirstArg]; ok {
if castedFirstArg, ok := agentTypeAliases[firstArg]; ok {
return castedFirstArg, nil
}
return AgentTypeCustom, nil
Expand Down Expand Up @@ -148,9 +144,9 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
}

var agentNames = (func() []string {
names := make([]string, 0, len(agentTypeMap))
for agentType := range agentTypeMap {
names = append(names, string(agentType))
names := make([]string, 0, len(agentTypeAliases))
for agentType := range agentTypeAliases {
names = append(names, agentType)
}
sort.Strings(names)
return names
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestParseAgentType(t *testing.T) {
{
firstArg: "cursor-agent",
agentTypeVar: "",
want: AgentTypeCursorAgent,
want: AgentTypeCursor,
},
{
firstArg: "cursor",
Expand All @@ -65,7 +65,7 @@ func TestParseAgentType(t *testing.T) {
{
firstArg: "q",
agentTypeVar: "",
want: AgentTypeQ,
want: AgentTypeAmazonQ,
},
{
firstArg: "auggie",
Expand Down Expand Up @@ -115,12 +115,12 @@ func TestParseAgentType(t *testing.T) {
{
firstArg: "claude",
agentTypeVar: "q",
want: AgentTypeQ,
want: AgentTypeAmazonQ,
},
{
firstArg: "claude",
agentTypeVar: "cursor-agent",
want: AgentTypeCursorAgent,
want: AgentTypeCursor,
},
{
firstArg: "claude",
Expand Down
28 changes: 11 additions & 17 deletions lib/msgfmt/msgfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func RemoveUserInput(msgRaw string, userInputRaw string, agentType AgentType) st
if idx, found := skipTrailingInputBoxLine(msgLines, lastUserInputLineIdx, "╯", "╰"); found {
lastUserInputLineIdx = idx
}
} else if agentType == AgentTypeCursorAgent || agentType == AgentTypeCursor {
} else if agentType == AgentTypeCursor {
if idx, found := skipTrailingInputBoxLine(msgLines, lastUserInputLineIdx, "┘", "└"); found {
lastUserInputLineIdx = idx
}
Expand Down Expand Up @@ -225,18 +225,16 @@ func trimEmptyLines(message string) string {
type AgentType string

const (
AgentTypeClaude AgentType = "claude"
AgentTypeGoose AgentType = "goose"
AgentTypeAider AgentType = "aider"
AgentTypeCodex AgentType = "codex"
AgentTypeGemini AgentType = "gemini"
AgentTypeAmp AgentType = "amp"
AgentTypeCursorAgent AgentType = "cursor-agent"
AgentTypeCursor AgentType = "cursor"
AgentTypeAuggie AgentType = "auggie"
AgentTypeAmazonQ AgentType = "amazonq"
AgentTypeQ AgentType = "q"
AgentTypeCustom AgentType = "custom"
AgentTypeClaude AgentType = "claude"
AgentTypeGoose AgentType = "goose"
AgentTypeAider AgentType = "aider"
AgentTypeCodex AgentType = "codex"
AgentTypeGemini AgentType = "gemini"
AgentTypeAmp AgentType = "amp"
AgentTypeCursor AgentType = "cursor"
AgentTypeAuggie AgentType = "auggie"
AgentTypeAmazonQ AgentType = "amazonq"
AgentTypeCustom AgentType = "custom"
)

func formatGenericMessage(message string, userInput string, agentType AgentType) string {
Expand Down Expand Up @@ -267,16 +265,12 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s
return formatGenericMessage(message, userInput, agentType)
case AgentTypeAmp:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeCursorAgent:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeCursor:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeAuggie:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeAmazonQ:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeQ:
return formatGenericMessage(message, userInput, agentType)
case AgentTypeCustom:
return formatGenericMessage(message, userInput, agentType)
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/msgfmt/msgfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestTrimEmptyLines(t *testing.T) {

func TestFormatAgentMessage(t *testing.T) {
dir := "testdata/format"
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeAmp, AgentTypeCodex, AgentTypeCursorAgent, AgentTypeCursor, AgentTypeAuggie, AgentTypeQ, AgentTypeCustom}
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeCustom}
for _, agentType := range agentTypes {
t.Run(string(agentType), func(t *testing.T) {
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType)))
Expand Down