-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathclaude.go
More file actions
34 lines (29 loc) · 1.15 KB
/
claude.go
File metadata and controls
34 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cli
import (
mf "github.com/coder/agentapi/lib/cli/msgfmt"
st "github.com/coder/agentapi/lib/cli/screentracker"
)
func formatPaste(message string) []st.MessagePart {
return []st.MessagePart{
// Bracketed paste mode start sequence
st.MessagePartText{Content: "\x1b[200~", Hidden: true},
st.MessagePartText{Content: message},
// Bracketed paste mode end sequence
st.MessagePartText{Content: "\x1b[201~", Hidden: true},
}
}
func formatClaudeCodeMessage(message string) []st.MessagePart {
parts := make([]st.MessagePart, 0)
// janky hack: send a random character and then a backspace because otherwise
// Claude Code echoes the startSeq back to the terminal.
// This basically simulates a user typing and then removing the character.
parts = append(parts, st.MessagePartText{Content: "x\b", Hidden: true})
parts = append(parts, formatPaste(message)...)
return parts
}
func FormatMessage(agentType mf.AgentType, message string) []st.MessagePart {
message = mf.TrimWhitespace(message)
// for now Claude Code formatting seems to also work for Goose and Aider
// so we can use the same function for all three
return formatClaudeCodeMessage(message)
}