From 3695feb222f8331ec9c3eea6c3554ecb8a7c8355 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 21 Nov 2025 22:43:30 +0530 Subject: [PATCH 1/2] feat(amp): add msgfmt logic for amp module --- lib/msgfmt/message_box.go | 21 +++++++++++++++++++++ lib/msgfmt/msgfmt.go | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/msgfmt/message_box.go b/lib/msgfmt/message_box.go index ce4eeeec..82a26631 100644 --- a/lib/msgfmt/message_box.go +++ b/lib/msgfmt/message_box.go @@ -79,3 +79,24 @@ func removeOpencodeMessageBox(msg string) string { } return strings.Join(lines, "\n") } + +func removeAmpMessageBox(msg string) string { + lines := strings.Split(msg, "\n") + msgBoxEndFound := false + msgBoxStartIdx := len(lines) + for i := len(lines) - 1; i >= 0; i-- { + line := strings.TrimSpace(lines[i]) + if !msgBoxEndFound && strings.HasPrefix(line, "╰") && strings.HasSuffix(line, "╯") { + msgBoxEndFound = true + } + if msgBoxEndFound && strings.HasPrefix(line, "╭") && strings.HasSuffix(line, "╮") { + msgBoxStartIdx = i + break + } + } + formattedMsg := strings.Join(lines[:msgBoxStartIdx], "\n") + if len(formattedMsg) == 0 { + return "Welcome to Amp" + } + return formattedMsg +} diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index 0cf1ca8e..3fccc2c3 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -268,6 +268,13 @@ func formatOpencodeMessage(message string, userInput string) string { return message } +func formatAmpMessage(message string, userInput string) string { + message = RemoveUserInput(message, userInput, AgentTypeAmp) + message = removeAmpMessageBox(message) + message = trimEmptyLines(message) + return message +} + func FormatAgentMessage(agentType AgentType, message string, userInput string) string { switch agentType { case AgentTypeClaude: @@ -283,7 +290,7 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s case AgentTypeCopilot: return formatGenericMessage(message, userInput, agentType) case AgentTypeAmp: - return formatGenericMessage(message, userInput, agentType) + return formatAmpMessage(message, userInput) case AgentTypeCursor: return formatGenericMessage(message, userInput, agentType) case AgentTypeAuggie: From 670151c64c5d6cb7f20e8f065dca896305c2e4f0 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 21 Nov 2025 22:52:47 +0530 Subject: [PATCH 2/2] feat: update tests --- .../format/amp/first_message/expected.txt | 17 ++++- .../testdata/format/amp/first_message/msg.txt | 33 +++++++-- .../format/amp/multi-line-input/expected.txt | 14 ++-- .../format/amp/multi-line-input/msg.txt | 70 ++++++++++--------- .../format/amp/second_message/expected.txt | 9 +-- .../format/amp/second_message/msg.txt | 18 +++-- 6 files changed, 99 insertions(+), 62 deletions(-) diff --git a/lib/msgfmt/testdata/format/amp/first_message/expected.txt b/lib/msgfmt/testdata/format/amp/first_message/expected.txt index 09bc56eb..7023dd75 100644 --- a/lib/msgfmt/testdata/format/amp/first_message/expected.txt +++ b/lib/msgfmt/testdata/format/amp/first_message/expected.txt @@ -1 +1,16 @@ - Welcome to Amp \ No newline at end of file + .............. + .....:::::.......... Welcome to Amp + ....:::::::::::.......... + ....::::----::::::::....... + ...::::---------:::::::::..... Ctrl+O to execute commands + ...::::------------:::::::::... Type @ to mention files + ....::----=======-----::::::::... Ctrl+C to exit + ...:::---==========-----::::::... + ...::---====++++====-----:::::... + ...::--====++++++====----:::::.. Use the amp: help command for more information + ..::---===++++++====----::::... + ..:::--====+++++====----:::... + ..:::---==========---::::.. Smart mode now uses Gemini 3 Pro. + ..:::----===-----::::... + ...::::----:::::... + ............ \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/first_message/msg.txt b/lib/msgfmt/testdata/format/amp/first_message/msg.txt index c6e02c6f..f9fc1db3 100644 --- a/lib/msgfmt/testdata/format/amp/first_message/msg.txt +++ b/lib/msgfmt/testdata/format/amp/first_message/msg.txt @@ -1,5 +1,30 @@ - Welcome to Amp -╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file + + + + .............. + .....:::::.......... Welcome to Amp + ....:::::::::::.......... + ....::::----::::::::....... + ...::::---------:::::::::..... Ctrl+O to execute commands + ...::::------------:::::::::... Type @ to mention files + ....::----=======-----::::::::... Ctrl+C to exit + ...:::---==========-----::::::... + ...::---====++++====-----:::::... + ...::--====++++++====----:::::.. Use the amp: help command for more information + ..::---===++++++====----::::... + ..:::--====+++++====----:::... + ..:::---==========---::::.. Smart mode now uses Gemini 3 Pro. + ..:::----===-----::::... + ...::::----:::::... + ............ + + + + + +╭─smart (click or Ctrl+S to switch)─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ │ +│ │ +╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯ diff --git a/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt b/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt index 83d3fbd5..516298e2 100644 --- a/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt +++ b/lib/msgfmt/testdata/format/amp/multi-line-input/expected.txt @@ -1,13 +1,7 @@ -∴ 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. + ✓ Thinking ▶ - I should use the Grep tool to search for some unique parts of this code to locate the file. + ✓ Grep const messageInterval = setInterval\(fetchMessages, 1000 -✓ Grep Set up polling for messages and server status + ✓ Thinking ▶ -✓ 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 + ✓ Grep setInterval in chat \ 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 index b56a2981..650b33c1 100644 --- a/lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt +++ b/lib/msgfmt/testdata/format/amp/multi-line-input/msg.txt @@ -1,33 +1,37 @@ -┃ 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 + + + + ┃ 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 ▶ + + ✓ Grep const messageInterval = setInterval\(fetchMessages, 1000 + + ✓ Thinking ▶ + + ✓ Grep setInterval in chat + +╭─smart─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ │ +│ │ +╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯ + ∿ Waiting for response... Esc to cancel 2% of 983k \ No newline at end of file diff --git a/lib/msgfmt/testdata/format/amp/second_message/expected.txt b/lib/msgfmt/testdata/format/amp/second_message/expected.txt index 9315a819..7d681e67 100644 --- a/lib/msgfmt/testdata/format/amp/second_message/expected.txt +++ b/lib/msgfmt/testdata/format/amp/second_message/expected.txt @@ -1,8 +1,3 @@ -∴ 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. + ✓ Thinking ▶ - 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 + I am doing well and ready to help you with your software engineering tasks. How can I assist you with the agentapi repository today? \ 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 index 5a53bfe9..1f175692 100644 --- a/lib/msgfmt/testdata/format/amp/second_message/msg.txt +++ b/lib/msgfmt/testdata/format/amp/second_message/msg.txt @@ -1,10 +1,14 @@ -┃ 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. + ┃ How are you? -I'm ready to help you with your coding tasks. What would you like to work on? \ No newline at end of file + ✓ Thinking ▶ + + I am doing well and ready to help you with your software engineering tasks. How can I assist you with the agentapi repository today? + +╭─smart─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ │ +│ │ +╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯ + 1% of 983k \ No newline at end of file