Skip to content

Commit fea4035

Browse files
authored
feat: support GitHub Copilot (#103)
1 parent a9160eb commit fea4035

File tree

17 files changed

+461
-15
lines changed

17 files changed

+461
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AgentAPI
22

3-
Control [Claude Code](https://github.com/anthropics/claude-code), [AmazonQ](https://aws.amazon.com/developer/learning/q-developer-cli/), [Opencode](https://opencode.ai/), [Goose](https://github.com/block/goose), [Aider](https://github.com/Aider-AI/aider), [Gemini](https://github.com/google-gemini/gemini-cli), [Sourcegraph Amp](https://github.com/sourcegraph/amp-cli), [Codex](https://github.com/openai/codex), [Auggie](https://docs.augmentcode.com/cli/overview), and [Cursor CLI](https://cursor.com/en/cli) with an HTTP API.
3+
Control [Claude Code](https://github.com/anthropics/claude-code), [AmazonQ](https://aws.amazon.com/developer/learning/q-developer-cli/), [Opencode](https://opencode.ai/), [Goose](https://github.com/block/goose), [Aider](https://github.com/Aider-AI/aider), [Gemini](https://github.com/google-gemini/gemini-cli), [GitHub Copilot](https://github.com/github/copilot-cli), [Sourcegraph Amp](https://github.com/sourcegraph/amp-cli), [Codex](https://github.com/openai/codex), [Auggie](https://docs.augmentcode.com/cli/overview), and [Cursor CLI](https://cursor.com/en/cli) with an HTTP API.
44

55
![agentapi-chat](https://github.com/user-attachments/assets/57032c9f-4146-4b66-b219-09e38ab7690d)
66

@@ -65,7 +65,7 @@ agentapi server -- goose
6565
```
6666

6767
> [!NOTE]
68-
> When using Codex, Opencode, Gemini, Amp or CursorCLI, always specify the agent type explicitly (eg: `agentapi server --type=codex -- codex`), or message formatting may break.
68+
> When using Codex, Opencode, Copilot, Gemini, Amp or CursorCLI, always specify the agent type explicitly (eg: `agentapi server --type=codex -- codex`), or message formatting may break.
6969
7070
An OpenAPI schema is available in [openapi.json](openapi.json).
7171

cmd/server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
AgentTypeAider AgentType = msgfmt.AgentTypeAider
2929
AgentTypeCodex AgentType = msgfmt.AgentTypeCodex
3030
AgentTypeGemini AgentType = msgfmt.AgentTypeGemini
31+
AgentTypeCopilot AgentType = msgfmt.AgentTypeCopilot
3132
AgentTypeAmp AgentType = msgfmt.AgentTypeAmp
3233
AgentTypeCursor AgentType = msgfmt.AgentTypeCursor
3334
AgentTypeAuggie AgentType = msgfmt.AgentTypeAuggie
@@ -43,6 +44,7 @@ var agentTypeAliases = map[string]AgentType{
4344
"aider": AgentTypeAider,
4445
"codex": AgentTypeCodex,
4546
"gemini": AgentTypeGemini,
47+
"copilot": AgentTypeCopilot,
4648
"amp": AgentTypeAmp,
4749
"auggie": AgentTypeAuggie,
4850
"cursor": AgentTypeCursor,

cmd/server/server_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func TestParseAgentType(t *testing.T) {
4747
agentTypeVar: "",
4848
want: AgentTypeGemini,
4949
},
50+
{
51+
firstArg: "copilot",
52+
agentTypeVar: "",
53+
want: AgentTypeCopilot,
54+
},
5055
{
5156
firstArg: "cursor-agent",
5257
agentTypeVar: "",
@@ -102,6 +107,11 @@ func TestParseAgentType(t *testing.T) {
102107
agentTypeVar: "goose",
103108
want: AgentTypeGoose,
104109
},
110+
{
111+
firstArg: "claude",
112+
agentTypeVar: "copilot",
113+
want: AgentTypeCopilot,
114+
},
105115
{
106116
firstArg: "goose",
107117
agentTypeVar: "claude",

lib/msgfmt/msgfmt.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func RemoveUserInput(msgRaw string, userInputRaw string, agentType AgentType) st
188188
lastUserInputLineIdx := msgRuneLineLocations[userInputEndIdx]
189189

190190
// Skip Gemini/Cursor trailing input box line
191-
if agentType == AgentTypeGemini {
191+
if agentType == AgentTypeGemini || agentType == AgentTypeCopilot {
192192
if idx, found := skipTrailingInputBoxLine(msgLines, lastUserInputLineIdx, "╯", "╰"); found {
193193
lastUserInputLineIdx = idx
194194
}
@@ -232,17 +232,18 @@ func trimEmptyLines(message string) string {
232232
type AgentType string
233233

234234
const (
235-
AgentTypeClaude AgentType = "claude"
236-
AgentTypeGoose AgentType = "goose"
237-
AgentTypeAider AgentType = "aider"
238-
AgentTypeCodex AgentType = "codex"
239-
AgentTypeGemini AgentType = "gemini"
240-
AgentTypeAmp AgentType = "amp"
241-
AgentTypeCursor AgentType = "cursor"
242-
AgentTypeAuggie AgentType = "auggie"
243-
AgentTypeAmazonQ AgentType = "amazonq"
244-
AgentTypeOpencode AgentType = "opencode"
245-
AgentTypeCustom AgentType = "custom"
235+
AgentTypeClaude AgentType = "claude"
236+
AgentTypeGoose AgentType = "goose"
237+
AgentTypeAider AgentType = "aider"
238+
AgentTypeCodex AgentType = "codex"
239+
AgentTypeGemini AgentType = "gemini"
240+
AgentTypeCopilot AgentType = "copilot"
241+
AgentTypeAmp AgentType = "amp"
242+
AgentTypeCursor AgentType = "cursor"
243+
AgentTypeAuggie AgentType = "auggie"
244+
AgentTypeAmazonQ AgentType = "amazonq"
245+
AgentTypeOpencode AgentType = "opencode"
246+
AgentTypeCustom AgentType = "custom"
246247
)
247248

248249
func formatGenericMessage(message string, userInput string, agentType AgentType) string {
@@ -278,6 +279,8 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s
278279
return formatCodexMessage(message, userInput)
279280
case AgentTypeGemini:
280281
return formatGenericMessage(message, userInput, agentType)
282+
case AgentTypeCopilot:
283+
return formatGenericMessage(message, userInput, agentType)
281284
case AgentTypeAmp:
282285
return formatGenericMessage(message, userInput, agentType)
283286
case AgentTypeCursor:

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, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeOpencode, AgentTypeCustom}
221+
agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeCopilot, AgentTypeAmp, AgentTypeCodex, AgentTypeCursor, AgentTypeAuggie, AgentTypeAmazonQ, AgentTypeOpencode, 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)))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
● I'll search for this code in the repository to find which file it belongs to.
2+
3+
○ Search for files containing the useEffect code with polling setup
4+
$ find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | xargs grep -l "useEffect.*checkServerStatus\|Set up polling for messages and server status" 2>/dev/null
5+
↪ 1 line...
6+
7+
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
8+
│ Search for files containing the useEffect code with polling setup: │
9+
│ │
10+
│ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
11+
│ │ find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | xargs grep -l "useEffect.*checkServerStatus\|Set up polling for messages and server status" 2>/dev/null │ │
12+
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
13+
│ │
14+
│ Do you want to run this command? │
15+
│ │
16+
│ ❯ 1. Yes │
17+
│ 2. Yes, and approve `xargs` for the rest of the running session │
18+
│ 3. No, and tell Copilot what to do differently (Esc) │
19+
│ │
20+
│ Confirm with number keys or ↑↓ keys and Enter, Cancel with Esc │
21+
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

0 commit comments

Comments
 (0)