diff --git a/format_rich_log.go b/format_rich_log.go index 2cd4092..5fe02b8 100644 --- a/format_rich_log.go +++ b/format_rich_log.go @@ -29,43 +29,48 @@ func main() { log.Fatalf("Error unmarshaling log file %s: %v", filename, err) } + // Iterate through the top-level Chat messages, which are now named groups. for _, chat := range logData.GetChats() { - author := chat.GetFrom().String() + fmt.Printf("\n========================================================\n") + fmt.Printf("== Chat Topic: %s\n", chat.GetChatName()) + fmt.Printf("========================================================\n\n") - // Handle content: prefer content_file, fallback to content. - var content string - if contentFile := chat.GetContentFile(); contentFile != "" { - // Construct the full path relative to the log file's directory. - logDir := filepath.Dir(filename) - contentPath := filepath.Join(logDir, contentFile) + // Iterate through the entries within this named chat group. + for _, entry := range chat.GetEntries() { + author := entry.GetFrom().String() - contentBytes, err := os.ReadFile(contentPath) - if err != nil { - content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err) + // Handle content: prefer content_file, fallback to content. + var content string + if contentFile := entry.GetContentFile(); contentFile != "" { + logDir := filepath.Dir(filename) + contentPath := filepath.Join(logDir, contentFile) + + contentBytes, err := os.ReadFile(contentPath) + if err != nil { + content = fmt.Sprintf("---\t ERROR: Could not read content file %s: %v ---", contentPath, err) + } else { + content = string(contentBytes) + } } else { - content = string(contentBytes) + content = entry.GetContent() // Fallback for older formats or inline content } - } else { - // Fallback for older log formats. - content = chat.GetContent() - } - // Print the conversational content first. - if content != "" { - // Trim trailing newlines for cleaner output. - fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content)) - } + // Print the conversational content first. + if content != "" { + fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content)) + } - // Now, format and print any tool calls. - for _, toolCall := range chat.GetToolCalls() { - printToolCallBox(toolCall) - } + // Now, format and print any tool calls. + for _, toolCall := range entry.GetToolCalls() { + printToolCallBox(toolCall) + } - // Handle the new CodeSnippet field. - if snippets := chat.GetSnippets(); snippets != nil { - logDir := filepath.Dir(filename) - for _, snippet := range snippets { - printCodeSnippet(snippet, logDir) + // Handle the CodeSnippet field. + if snippets := entry.GetSnippets(); snippets != nil { + logDir := filepath.Dir(filename) + for _, snippet := range snippets { + printCodeSnippet(snippet, logDir) + } } } } diff --git a/log/2025-08-22-refactor.text b/log/2025-08-22-refactor.text new file mode 100644 index 0000000..ccb0c3f --- /dev/null +++ b/log/2025-08-22-refactor.text @@ -0,0 +1,15 @@ +uuid: "refactor-log-01" +version: "v0.0.5 go.wit.com/lib/protobuf/chatpb" +Chats: { + ChatName: "Conversation Refactoring" + Entries: { + from: USER + ctime: { seconds: 1724172000 } + ContentFile: "content/refactor_q1.content" + } + Entries: { + from: GEMINI + ctime: { seconds: 1724172060 } + ContentFile: "content/refactor_a1.content" + } +} diff --git a/log/content/refactor_a1.content b/log/content/refactor_a1.content new file mode 100644 index 0000000..a559677 --- /dev/null +++ b/log/content/refactor_a1.content @@ -0,0 +1 @@ +Excellent. This is a great architectural change. It makes the log files much more organized by grouping related conversations under a named topic. I will proceed with updating the code to use this new, clearer structure. \ No newline at end of file diff --git a/log/content/refactor_q1.content b/log/content/refactor_q1.content new file mode 100644 index 0000000..ecb305b --- /dev/null +++ b/log/content/refactor_q1.content @@ -0,0 +1 @@ +I changed the chat.proto in a new way. I want to have a Chat to have a name like "BACnet" or "shell". Then, move the exist *Chat things into Entries. I made a new ChatEntry that has the sames fields as Chat. Can you try to change the code to use this new way of doing things? \ No newline at end of file