-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathclaude.go
More file actions
39 lines (34 loc) · 1.45 KB
/
claude.go
File metadata and controls
39 lines (34 loc) · 1.45 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
35
36
37
38
39
package httpapi
import (
mf "github.com/coder/agentapi/lib/msgfmt"
st "github.com/coder/agentapi/lib/screentracker"
)
// formatPaste wraps message in bracketed paste escape sequences.
// These sequences start with ESC (\x1b), which TUI selection
// widgets (e.g. Claude Code's numbered-choice prompt) interpret
// as "cancel". For selection prompts, callers should use
// MessageTypeRaw to send raw keystrokes directly instead.
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)
}