diff --git a/cmd/notes.go b/cmd/notes.go index f69916e..434437f 100644 --- a/cmd/notes.go +++ b/cmd/notes.go @@ -166,13 +166,38 @@ func printConversationMarkdown(note notes.ConversationNote, commit string) { // Conversation excerpt if note.ConversationExcerpt != "" { fmt.Printf("## Conversation Context\n\n") - fmt.Printf("%s\n\n", note.ConversationExcerpt) + // Clean up and format the conversation excerpt for better readability + formatted := formatConversationExcerpt(note.ConversationExcerpt) + fmt.Printf("%s\n\n", formatted) } fmt.Printf("---\n") fmt.Printf("💡 *Generated by Claude Code hooks system*\n") } +// formatConversationExcerpt cleans up the conversation excerpt for better readability +func formatConversationExcerpt(excerpt string) string { + // Replace escaped newlines with actual newlines + formatted := strings.ReplaceAll(excerpt, "\\n", "\n") + + // Replace escaped quotes with regular quotes + formatted = strings.ReplaceAll(formatted, "\\\"", "\"") + + // Replace escaped backslashes + formatted = strings.ReplaceAll(formatted, "\\\\", "\\") + + // Clean up common JSON escape sequences + formatted = strings.ReplaceAll(formatted, "\\t", " ") // tabs to spaces + formatted = strings.ReplaceAll(formatted, "\\r", "") // remove carriage returns + + // Fix any double newlines that might have been created + for strings.Contains(formatted, "\n\n\n") { + formatted = strings.ReplaceAll(formatted, "\n\n\n", "\n\n") + } + + return strings.TrimSpace(formatted) +} + // getCommitInfo returns formatted commit information func getCommitInfo(commit string) string { cmd := exec.Command("git", "log", "--oneline", "-1", commit)