Skip to content

Commit f71b1c0

Browse files
authored
feat(amp): add msgfmt logic for amp module (#147)
1 parent 7a9abbb commit f71b1c0

File tree

8 files changed

+128
-63
lines changed

8 files changed

+128
-63
lines changed

lib/msgfmt/message_box.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,24 @@ func removeOpencodeMessageBox(msg string) string {
7979
}
8080
return strings.Join(lines, "\n")
8181
}
82+
83+
func removeAmpMessageBox(msg string) string {
84+
lines := strings.Split(msg, "\n")
85+
msgBoxEndFound := false
86+
msgBoxStartIdx := len(lines)
87+
for i := len(lines) - 1; i >= 0; i-- {
88+
line := strings.TrimSpace(lines[i])
89+
if !msgBoxEndFound && strings.HasPrefix(line, "╰") && strings.HasSuffix(line, "╯") {
90+
msgBoxEndFound = true
91+
}
92+
if msgBoxEndFound && strings.HasPrefix(line, "╭") && strings.HasSuffix(line, "╮") {
93+
msgBoxStartIdx = i
94+
break
95+
}
96+
}
97+
formattedMsg := strings.Join(lines[:msgBoxStartIdx], "\n")
98+
if len(formattedMsg) == 0 {
99+
return "Welcome to Amp"
100+
}
101+
return formattedMsg
102+
}

lib/msgfmt/msgfmt.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ func formatOpencodeMessage(message string, userInput string) string {
268268
return message
269269
}
270270

271+
func formatAmpMessage(message string, userInput string) string {
272+
message = RemoveUserInput(message, userInput, AgentTypeAmp)
273+
message = removeAmpMessageBox(message)
274+
message = trimEmptyLines(message)
275+
return message
276+
}
277+
271278
func FormatAgentMessage(agentType AgentType, message string, userInput string) string {
272279
switch agentType {
273280
case AgentTypeClaude:
@@ -283,7 +290,7 @@ func FormatAgentMessage(agentType AgentType, message string, userInput string) s
283290
case AgentTypeCopilot:
284291
return formatGenericMessage(message, userInput, agentType)
285292
case AgentTypeAmp:
286-
return formatGenericMessage(message, userInput, agentType)
293+
return formatAmpMessage(message, userInput)
287294
case AgentTypeCursor:
288295
return formatGenericMessage(message, userInput, agentType)
289296
case AgentTypeAuggie:
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
Welcome to Amp
1+
..............
2+
.....:::::.......... Welcome to Amp
3+
....:::::::::::..........
4+
....::::----::::::::.......
5+
...::::---------:::::::::..... Ctrl+O to execute commands
6+
...::::------------:::::::::... Type @ to mention files
7+
....::----=======-----::::::::... Ctrl+C to exit
8+
...:::---==========-----::::::...
9+
...::---====++++====-----:::::...
10+
...::--====++++++====----:::::.. Use the amp: help command for more information
11+
..::---===++++++====----::::...
12+
..:::--====+++++====----:::...
13+
..:::---==========---::::.. Smart mode now uses Gemini 3 Pro.
14+
..:::----===-----::::...
15+
...::::----:::::...
16+
............
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
Welcome to Amp
21

3-
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
4-
│ │
5-
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
2+
3+
4+
5+
..............
6+
.....:::::.......... Welcome to Amp
7+
....:::::::::::..........
8+
....::::----::::::::.......
9+
...::::---------:::::::::..... Ctrl+O to execute commands
10+
...::::------------:::::::::... Type @ to mention files
11+
....::----=======-----::::::::... Ctrl+C to exit
12+
...:::---==========-----::::::...
13+
...::---====++++====-----:::::...
14+
...::--====++++++====----:::::.. Use the amp: help command for more information
15+
..::---===++++++====----::::...
16+
..:::--====+++++====----:::...
17+
..:::---==========---::::.. Smart mode now uses Gemini 3 Pro.
18+
..:::----===-----::::...
19+
...::::----:::::...
20+
............
21+
22+
23+
24+
25+
26+
╭─smart (click or Ctrl+S to switch)─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
27+
│ │
28+
│ │
29+
│ │
30+
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
∴ Thinking
2-
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
3-
for messages and server status. I need to search for this code in the codebase to find the file it belongs to.
1+
✓ Thinking ▶
42

5-
I should use the Grep tool to search for some unique parts of this code to locate the file.
3+
Grep const messageInterval = setInterval\(fetchMessages, 1000
64

7-
✓ Grep Set up polling for messages and server status
5+
✓ Thinking ▶
86

9-
✓ Grep const messageInterval = setInterval\(fetchMessages, 1000\)
10-
11-
✓ List Directory /mnt/c/Users/Username/test-amp
12-
13-
No files found in the workspace containing this code.
7+
✓ Grep setInterval in chat
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
┃ Which file is this code from?
2-
3-
┃ ```ts
4-
┃ // Set up polling for messages and server status
5-
┃ useEffect(() => {
6-
┃ // Check server status initially
7-
┃ checkServerStatus();
8-
9-
┃ // Set up polling intervals
10-
┃ const messageInterval = setInterval(fetchMessages, 1000);
11-
┃ const statusInterval = setInterval(checkServerStatus, 250);
12-
13-
┃ // Clean up intervals on component unmount
14-
┃ return () => {
15-
┃ clearInterval(messageInterval);
16-
┃ clearInterval(statusInterval);
17-
┃ };
18-
┃ }, []);
19-
┃ ```
20-
21-
∴ Thinking
22-
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
23-
for messages and server status. I need to search for this code in the codebase to find the file it belongs to.
24-
25-
I should use the Grep tool to search for some unique parts of this code to locate the file.
26-
27-
✓ Grep Set up polling for messages and server status
28-
29-
✓ Grep const messageInterval = setInterval\(fetchMessages, 1000\)
30-
31-
✓ List Directory /mnt/c/Users/Username/test-amp
32-
33-
No files found in the workspace containing this code.
1+
2+
3+
4+
┃ Which file is this code from?
5+
6+
┃ ```ts
7+
┃ // Set up polling for messages and server status
8+
┃ useEffect(() => {
9+
┃ // Check server status initially
10+
┃ checkServerStatus();
11+
12+
┃ // Set up polling intervals
13+
┃ const messageInterval = setInterval(fetchMessages, 1000);
14+
┃ const statusInterval = setInterval(checkServerStatus, 250);
15+
16+
┃ // Clean up intervals on component unmount
17+
┃ return () => {
18+
┃ clearInterval(messageInterval);
19+
┃ clearInterval(statusInterval);
20+
┃ };
21+
┃ }, []);
22+
┃ ```
23+
24+
✓ Thinking ▶
25+
26+
✓ Grep const messageInterval = setInterval\(fetchMessages, 1000
27+
28+
✓ Thinking ▶
29+
30+
✓ Grep setInterval in chat
31+
32+
╭─smart─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
33+
│ │
34+
│ │
35+
│ │
36+
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯
37+
∿ Waiting for response... Esc to cancel 2% of 983k
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
∴ Thinking
2-
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
3-
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
4-
greeting.
1+
✓ Thinking ▶
52

6-
I should avoid elaborate explanations or summaries, and just give a brief, direct response.
7-
8-
I'm ready to help you with your coding tasks. What would you like to work on?
3+
I am doing well and ready to help you with your software engineering tasks. How can I assist you with the agentapi repository today?
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
┃ How are you?
21

3-
∴ Thinking
4-
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
5-
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
6-
greeting.
72

8-
I should avoid elaborate explanations or summaries, and just give a brief, direct response.
3+
┃ How are you?
94

10-
I'm ready to help you with your coding tasks. What would you like to work on?
5+
✓ Thinking ▶
6+
7+
I am doing well and ready to help you with your software engineering tasks. How can I assist you with the agentapi repository today?
8+
9+
╭─smart─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
10+
│ │
11+
│ │
12+
│ │
13+
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────~/Documents/work/agentapi (fix-amp-formatting)─╯
14+
1% of 983k

0 commit comments

Comments
 (0)