From 7948265a1b397da6e155155cb2f93fa340580a76 Mon Sep 17 00:00:00 2001 From: Harsh panwar Date: Tue, 5 Aug 2025 20:34:28 +0530 Subject: [PATCH 1/3] support Sourcegraph Amp cli --- README.md | 3 +- cmd/root.go | 2 +- cmd/server/server.go | 2 ++ cmd/server/server_test.go | 5 +++ lib/msgfmt/msgfmt.go | 3 ++ lib/msgfmt/msgfmt_test.go | 2 +- .../format/amp/first_massage/expected.txt | 1 + .../testdata/format/amp/first_massage/msg.txt | 5 +++ .../format/amp/first_massage/user.txt | 0 .../format/amp/multi-line-input/expected.txt | 13 ++++++++ .../format/amp/multi-line-input/msg.txt | 33 +++++++++++++++++++ .../format/amp/multi-line-input/user.txt | 19 +++++++++++ .../format/amp/second_message/expected.txt | 1 + .../format/amp/second_message/msg.txt | 10 ++++++ .../format/amp/second_message/user.txt | 1 + 15 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 lib/msgfmt/testdata/format/amp/first_massage/expected.txt create mode 100644 lib/msgfmt/testdata/format/amp/first_massage/msg.txt create mode 100644 lib/msgfmt/testdata/format/amp/first_massage/user.txt create mode 100644 lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt create mode 100644 lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt create mode 100644 lib/msgfmt/testdata/format/amp/multi-line-input/user.txt create mode 100644 lib/msgfmt/testdata/format/amp/second_message/expected.txt create mode 100644 lib/msgfmt/testdata/format/amp/second_message/msg.txt create mode 100644 lib/msgfmt/testdata/format/amp/second_message/user.txt diff --git a/README.md b/README.md index 77c571f..5bc64bc 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # AgentAPI -Control [Claude Code](https://github.com/anthropics/claude-code), [Goose](https://github.com/block/goose), [Aider](https://github.com/Aider-AI/aider), [Gemini](https://github.com/google-gemini/gemini-cli) and [Codex](https://github.com/openai/codex) with an HTTP API. +Control [Claude Code](https://github.com/anthropics/claude-code), [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) and [Codex](https://github.com/openai/codex) with an HTTP API. ![agentapi-chat](https://github.com/user-attachments/assets/57032c9f-4146-4b66-b219-09e38ab7690d) - You can use AgentAPI: - to build a unified chat interface for coding agents diff --git a/cmd/root.go b/cmd/root.go index 7f12a80..955469e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( var rootCmd = &cobra.Command{ Use: "agentapi", Short: "AgentAPI CLI", - Long: `AgentAPI - HTTP API for Claude Code, Goose, Aider, Gemini and Codex`, + Long: `AgentAPI - HTTP API for Claude Code, Goose, Aider, Gemini, Sourcegraph Amp and Codex`, Version: "0.3.2", } diff --git a/cmd/server/server.go b/cmd/server/server.go index 4fc3943..7240593 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -36,6 +36,7 @@ const ( AgentTypeAider AgentType = msgfmt.AgentTypeAider AgentTypeCodex AgentType = msgfmt.AgentTypeCodex AgentTypeGemini AgentType = msgfmt.AgentTypeGemini + AgentTypeAmp AgentType = msgfmt.AgentTypeAmp AgentTypeCustom AgentType = msgfmt.AgentTypeCustom ) @@ -46,6 +47,7 @@ var agentTypeMap = map[AgentType]bool{ AgentTypeAider: true, AgentTypeCodex: true, AgentTypeGemini: true, + AgentTypeAmp: true, AgentTypeCustom: true, } diff --git a/cmd/server/server_test.go b/cmd/server/server_test.go index ff0611e..e21b36f 100644 --- a/cmd/server/server_test.go +++ b/cmd/server/server_test.go @@ -28,6 +28,11 @@ func TestParseAgentType(t *testing.T) { agentTypeVar: "", want: AgentTypeGemini, }, + { + firstArg: "amp", + agentTypeVar: "", + want: AgentTypeAmp, + }, { firstArg: "goose", agentTypeVar: "", diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index 3560aa7..a3cdd57 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -206,6 +206,7 @@ const ( AgentTypeAider AgentType = "aider" AgentTypeCodex AgentType = "codex" AgentTypeGemini AgentType = "gemini" + AgentTypeAmp AgentType = "amp" AgentTypeCustom AgentType = "custom" ) @@ -236,6 +237,8 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s return formatCodexMessage(message, userInput) case AgentTypeGemini: return formatGenericMessage(message, userInput) + case AgentTypeAmp: + return formatGenericMessage(message, userInput) case AgentTypeCustom: return formatGenericMessage(message, userInput) default: diff --git a/lib/msgfmt/msgfmt_test.go b/lib/msgfmt/msgfmt_test.go index b02cbbc..837ff52 100644 --- a/lib/msgfmt/msgfmt_test.go +++ b/lib/msgfmt/msgfmt_test.go @@ -218,7 +218,7 @@ func TestTrimEmptyLines(t *testing.T) { func TestFormatAgentMessage(t *testing.T) { dir := "testdata/format" - agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeCodex, AgentTypeCustom} + agentTypes := []AgentType{AgentTypeClaude, AgentTypeGoose, AgentTypeAider, AgentTypeGemini, AgentTypeAmp, AgentTypeCodex, AgentTypeCustom} for _, agentType := range agentTypes { t.Run(string(agentType), func(t *testing.T) { cases, err := testdataDir.ReadDir(path.Join(dir, string(agentType))) diff --git a/lib/msgfmt/testdata/format/amp/first_massage/expected.txt b/lib/msgfmt/testdata/format/amp/first_massage/expected.txt new file mode 100644 index 0000000..09bc56e --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/first_massage/expected.txt @@ -0,0 +1 @@ + Welcome to Amp \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/first_massage/msg.txt b/lib/msgfmt/testdata/format/amp/first_massage/msg.txt new file mode 100644 index 0000000..c6e02c6 --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/first_massage/msg.txt @@ -0,0 +1,5 @@ + Welcome to Amp + +╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/first_massage/user.txt b/lib/msgfmt/testdata/format/amp/first_massage/user.txt new file mode 100644 index 0000000..e69de29 diff --git a/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt b/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt new file mode 100644 index 0000000..83d3fbd --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt @@ -0,0 +1,13 @@ +∴ Thinking + The user is asking me to identify which file contains this specific TypeScript code snippet. The code shows a useEffect hook that sets up polling +for messages and server status. I need to search for this code in the codebase to find the file it belongs to. + + I should use the Grep tool to search for some unique parts of this code to locate the file. + +✓ Grep Set up polling for messages and server status + +✓ Grep const messageInterval = setInterval\(fetchMessages, 1000\) + +✓ List Directory /mnt/c/Users/Username/test-amp + +No files found in the workspace containing this code. \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt b/lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt new file mode 100644 index 0000000..b56a298 --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt @@ -0,0 +1,33 @@ +┃ Which file is this code from? +┃ +┃ ```ts +┃ // Set up polling for messages and server status +┃ useEffect(() => { +┃ // Check server status initially +┃ checkServerStatus(); +┃ +┃ // Set up polling intervals +┃ const messageInterval = setInterval(fetchMessages, 1000); +┃ const statusInterval = setInterval(checkServerStatus, 250); +┃ +┃ // Clean up intervals on component unmount +┃ return () => { +┃ clearInterval(messageInterval); +┃ clearInterval(statusInterval); +┃ }; +┃ }, []); +┃ ``` + +∴ Thinking + The user is asking me to identify which file contains this specific TypeScript code snippet. The code shows a useEffect hook that sets up polling +for messages and server status. I need to search for this code in the codebase to find the file it belongs to. + + I should use the Grep tool to search for some unique parts of this code to locate the file. + +✓ Grep Set up polling for messages and server status + +✓ Grep const messageInterval = setInterval\(fetchMessages, 1000\) + +✓ List Directory /mnt/c/Users/Username/test-amp + +No files found in the workspace containing this code. \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/multi-line-input/user.txt b/lib/msgfmt/testdata/format/amp/multi-line-input/user.txt new file mode 100644 index 0000000..c3b14b0 --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/multi-line-input/user.txt @@ -0,0 +1,19 @@ +Which file is this code from? + +```ts +// Set up polling for messages and server status +useEffect(() => { + // Check server status initially + checkServerStatus(); + + // Set up polling intervals + const messageInterval = setInterval(fetchMessages, 1000); + const statusInterval = setInterval(checkServerStatus, 250); + + // Clean up intervals on component unmount + return () => { + clearInterval(messageInterval); + clearInterval(statusInterval); + }; +}, []); +``` diff --git a/lib/msgfmt/testdata/format/amp/second_message/expected.txt b/lib/msgfmt/testdata/format/amp/second_message/expected.txt new file mode 100644 index 0000000..2bac726 --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/second_message/expected.txt @@ -0,0 +1 @@ +I'm ready to help you with your coding tasks. What would you like to work on? \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/second_message/msg.txt b/lib/msgfmt/testdata/format/amp/second_message/msg.txt new file mode 100644 index 0000000..5a53bfe --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/second_message/msg.txt @@ -0,0 +1,10 @@ +┃ How are you? + +∴ Thinking + The user is asking a simple social greeting "How are you?". This is a casual question about my state/wellbeing. I should respond concisely and +directly as per my instructions to keep responses short (fewer than 4 lines unless asked for detail). I don't need to use any tools for this simple +greeting. + + I should avoid elaborate explanations or summaries, and just give a brief, direct response. + +I'm ready to help you with your coding tasks. What would you like to work on? \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/second_message/user.txt b/lib/msgfmt/testdata/format/amp/second_message/user.txt new file mode 100644 index 0000000..3099b43 --- /dev/null +++ b/lib/msgfmt/testdata/format/amp/second_message/user.txt @@ -0,0 +1 @@ +How are you? \ No newline at end of file From 6fad602f413211c024538b27ff4e280e121964c4 Mon Sep 17 00:00:00 2001 From: Harsh panwar Date: Thu, 7 Aug 2025 21:38:55 +0530 Subject: [PATCH 2/3] Fix typo --- .../format/amp/{first_massage => first_message}/expected.txt | 0 .../testdata/format/amp/{first_massage => first_message}/msg.txt | 0 .../testdata/format/amp/{first_massage => first_message}/user.txt | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename lib/msgfmt/testdata/format/amp/{first_massage => first_message}/expected.txt (100%) rename lib/msgfmt/testdata/format/amp/{first_massage => first_message}/msg.txt (100%) rename lib/msgfmt/testdata/format/amp/{first_massage => first_message}/user.txt (100%) diff --git a/lib/msgfmt/testdata/format/amp/first_massage/expected.txt b/lib/msgfmt/testdata/format/amp/first_message/expected.txt similarity index 100% rename from lib/msgfmt/testdata/format/amp/first_massage/expected.txt rename to lib/msgfmt/testdata/format/amp/first_message/expected.txt diff --git a/lib/msgfmt/testdata/format/amp/first_massage/msg.txt b/lib/msgfmt/testdata/format/amp/first_message/msg.txt similarity index 100% rename from lib/msgfmt/testdata/format/amp/first_massage/msg.txt rename to lib/msgfmt/testdata/format/amp/first_message/msg.txt diff --git a/lib/msgfmt/testdata/format/amp/first_massage/user.txt b/lib/msgfmt/testdata/format/amp/first_message/user.txt similarity index 100% rename from lib/msgfmt/testdata/format/amp/first_massage/user.txt rename to lib/msgfmt/testdata/format/amp/first_message/user.txt From 8d00b413ae58460da45d1b8ca5dc22f6ef63b155 Mon Sep 17 00:00:00 2001 From: Harsh panwar Date: Fri, 8 Aug 2025 06:35:39 +0530 Subject: [PATCH 3/3] fix test --- lib/msgfmt/testdata/format/amp/second_message/expected.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/msgfmt/testdata/format/amp/second_message/expected.txt b/lib/msgfmt/testdata/format/amp/second_message/expected.txt index 2bac726..9315a81 100644 --- a/lib/msgfmt/testdata/format/amp/second_message/expected.txt +++ b/lib/msgfmt/testdata/format/amp/second_message/expected.txt @@ -1 +1,8 @@ +∴ Thinking + The user is asking a simple social greeting "How are you?". This is a casual question about my state/wellbeing. I should respond concisely and +directly as per my instructions to keep responses short (fewer than 4 lines unless asked for detail). I don't need to use any tools for this simple +greeting. + + I should avoid elaborate explanations or summaries, and just give a brief, direct response. + I'm ready to help you with your coding tasks. What would you like to work on? \ No newline at end of file