Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0876f7d

Browse files
authored
feat: support agent type aliases (#81)
1 parent bf7acf8 commit 0876f7d

File tree

19 files changed

+45
-55
lines changed

19 files changed

+45
-55
lines changed

‎cmd/server/server.go‎

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,44 @@ import (
2323
type AgentType = msgfmt.AgentType
2424

2525
const (
26-
AgentTypeClaude AgentType = msgfmt.AgentTypeClaude
27-
AgentTypeGoose AgentType = msgfmt.AgentTypeGoose
28-
AgentTypeAider AgentType = msgfmt.AgentTypeAider
29-
AgentTypeCodex AgentType = msgfmt.AgentTypeCodex
30-
AgentTypeGemini AgentType = msgfmt.AgentTypeGemini
31-
AgentTypeAmp AgentType = msgfmt.AgentTypeAmp
32-
AgentTypeCursorAgent AgentType = msgfmt.AgentTypeCursorAgent
33-
AgentTypeCursor AgentType = msgfmt.AgentTypeCursor
34-
AgentTypeAuggie AgentType = msgfmt.AgentTypeAuggie
35-
AgentTypeAmazonQ AgentType = msgfmt.AgentTypeAmazonQ
36-
AgentTypeQ AgentType = msgfmt.AgentTypeQ
37-
AgentTypeCustom AgentType = msgfmt.AgentTypeCustom
26+
AgentTypeClaude AgentType = msgfmt.AgentTypeClaude
27+
AgentTypeGoose AgentType = msgfmt.AgentTypeGoose
28+
AgentTypeAider AgentType = msgfmt.AgentTypeAider
29+
AgentTypeCodex AgentType = msgfmt.AgentTypeCodex
30+
AgentTypeGemini AgentType = msgfmt.AgentTypeGemini
31+
AgentTypeAmp AgentType = msgfmt.AgentTypeAmp
32+
AgentTypeCursor AgentType = msgfmt.AgentTypeCursor
33+
AgentTypeAuggie AgentType = msgfmt.AgentTypeAuggie
34+
AgentTypeAmazonQ AgentType = msgfmt.AgentTypeAmazonQ
35+
AgentTypeCustom AgentType = msgfmt.AgentTypeCustom
3836
)
3937

40-
// exhaustiveness of this map is checked by the exhaustive linter
41-
var agentTypeMap = map[AgentType]bool{
42-
AgentTypeClaude: true,
43-
AgentTypeGoose: true,
44-
AgentTypeAider: true,
45-
AgentTypeCodex: true,
46-
AgentTypeGemini: true,
47-
AgentTypeAmp: true,
48-
AgentTypeCursorAgent: true,
49-
AgentTypeCursor: true,
50-
AgentTypeAuggie: true,
51-
AgentTypeAmazonQ: true,
52-
AgentTypeQ: true,
53-
AgentTypeCustom: true,
38+
// agentTypeAliases contains the mapping of possible input agent type strings to their canonical AgentType values
39+
var agentTypeAliases = map[string]AgentType{
40+
"claude": AgentTypeClaude,
41+
"goose": AgentTypeGoose,
42+
"aider": AgentTypeAider,
43+
"codex": AgentTypeCodex,
44+
"gemini": AgentTypeGemini,
45+
"amp": AgentTypeAmp,
46+
"auggie": AgentTypeAuggie,
47+
"cursor": AgentTypeCursor,
48+
"cursor-agent": AgentTypeCursor,
49+
"q": AgentTypeAmazonQ,
50+
"amazonq": AgentTypeAmazonQ,
51+
"custom": AgentTypeCustom,
5452
}
5553

5654
func parseAgentType(firstArg string, agentTypeVar string) (AgentType, error) {
5755
// if the agent type is provided, use it
58-
castedAgentType := AgentType(agentTypeVar)
59-
if _, ok := agentTypeMap[castedAgentType]; ok {
56+
if castedAgentType, ok := agentTypeAliases[agentTypeVar]; ok {
6057
return castedAgentType, nil
6158
}
6259
if agentTypeVar != "" {
6360
return AgentTypeCustom, fmt.Errorf("invalid agent type: %s", agentTypeVar)
6461
}
6562
// if the agent type is not provided, guess it from the first argument
66-
castedFirstArg := AgentType(firstArg)
67-
if _, ok := agentTypeMap[castedFirstArg]; ok {
63+
if castedFirstArg, ok := agentTypeAliases[firstArg]; ok {
6864
return castedFirstArg, nil
6965
}
7066
return AgentTypeCustom, nil
@@ -148,9 +144,9 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
148144
}
149145

150146
var agentNames = (func() []string {
151-
names := make([]string, 0, len(agentTypeMap))
152-
for agentType := range agentTypeMap {
153-
names = append(names, string(agentType))
147+
names := make([]string, 0, len(agentTypeAliases))
148+
for agentType := range agentTypeAliases {
149+
names = append(names, agentType)
154150
}
155151
sort.Strings(names)
156152
return names

‎cmd/server/server_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestParseAgentType(t *testing.T) {
5050
{
5151
firstArg: "cursor-agent",
5252
agentTypeVar: "",
53-
want: AgentTypeCursorAgent,
53+
want: AgentTypeCursor,
5454
},
5555
{
5656
firstArg: "cursor",
@@ -65,7 +65,7 @@ func TestParseAgentType(t *testing.T) {
6565
{
6666
firstArg: "q",
6767
agentTypeVar: "",
68-
want: AgentTypeQ,
68+
want: AgentTypeAmazonQ,
6969
},
7070
{
7171
firstArg: "auggie",
@@ -115,12 +115,12 @@ func TestParseAgentType(t *testing.T) {
115115
{
116116
firstArg: "claude",
117117
agentTypeVar: "q",
118-
want: AgentTypeQ,
118+
want: AgentTypeAmazonQ,
119119
},
120120
{
121121
firstArg: "claude",
122122
agentTypeVar: "cursor-agent",
123-
want: AgentTypeCursorAgent,
123+
want: AgentTypeCursor,
124124
},
125125
{
126126
firstArg: "claude",

‎lib/msgfmt/msgfmt.go‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func RemoveUserInput(msgRaw string, userInputRaw string, agentType AgentType) st
192192
if idx, found := skipTrailingInputBoxLine(msgLines, lastUserInputLineIdx, "╯", "╰"); found {
193193
lastUserInputLineIdx = idx
194194
}
195-
} else if agentType == AgentTypeCursorAgent||agentType==AgentTypeCursor {
195+
} else if agentType == AgentTypeCursor {
196196
if idx, found := skipTrailingInputBoxLine(msgLines, lastUserInputLineIdx, "┘", "└"); found {
197197
lastUserInputLineIdx = idx
198198
}
@@ -225,18 +225,16 @@ func trimEmptyLines(message string) string {
225225
type AgentType string
226226

227227
const (
228-
AgentTypeClaude AgentType = "claude"
229-
AgentTypeGoose AgentType = "goose"
230-
AgentTypeAider AgentType = "aider"
231-
AgentTypeCodex AgentType = "codex"
232-
AgentTypeGemini AgentType = "gemini"
233-
AgentTypeAmp AgentType = "amp"
234-
AgentTypeCursorAgent AgentType = "cursor-agent"
235-
AgentTypeCursor AgentType = "cursor"
236-
AgentTypeAuggie AgentType = "auggie"
237-
AgentTypeAmazonQ AgentType = "amazonq"
238-
AgentTypeQ AgentType = "q"
239-
AgentTypeCustom AgentType = "custom"
228+
AgentTypeClaude AgentType = "claude"
229+
AgentTypeGoose AgentType = "goose"
230+
AgentTypeAider AgentType = "aider"
231+
AgentTypeCodex AgentType = "codex"
232+
AgentTypeGemini AgentType = "gemini"
233+
AgentTypeAmp AgentType = "amp"
234+
AgentTypeCursor AgentType = "cursor"
235+
AgentTypeAuggie AgentType = "auggie"
236+
AgentTypeAmazonQ AgentType = "amazonq"
237+
AgentTypeCustom AgentType = "custom"
240238
)
241239

242240
func formatGenericMessage(message string, userInput string, agentType AgentType) string {
@@ -267,16 +265,12 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s
267265
return formatGenericMessage(message, userInput, agentType)
268266
case AgentTypeAmp:
269267
return formatGenericMessage(message, userInput, agentType)
270-
case AgentTypeCursorAgent:
271-
return formatGenericMessage(message, userInput, agentType)
272268
case AgentTypeCursor:
273269
return formatGenericMessage(message, userInput, agentType)
274270
case AgentTypeAuggie:
275271
return formatGenericMessage(message, userInput, agentType)
276272
case AgentTypeAmazonQ:
277273
return formatGenericMessage(message, userInput, agentType)
278-
case AgentTypeQ:
279-
return formatGenericMessage(message, userInput, agentType)
280274
case AgentTypeCustom:
281275
return formatGenericMessage(message, userInput, agentType)
282276
default:

‎lib/msgfmt/msgfmt_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func TestTrimEmptyLines(t *testing.T) {
218218

219219
func TestFormatAgentMessage(t *testing.T) {
220220
dir := "testdata/format"
221-
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeAmp, AgentTypeCodex, AgentTypeCursorAgent, AgentTypeCursor, AgentTypeAuggie, AgentTypeQ, AgentTypeCustom}
221+
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeCustom}
222222
for _, agentType := range agentTypes {
223223
t.Run(string(agentType), func(t *testing.T) {
224224
cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType)))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /