refactor: Restructure log format to group entries by topic

- Modify the protobuf schema to introduce a named 'Chat' topic
  that contains a list of 'ChatEntry' messages.
- This provides better organization for long conversations.
- Update the Go log formatter to handle this new nested structure,
  printing a header for each topic.
- Add a new log file demonstrating the refactored format.
This commit is contained in:
Castor Gemini 2025-08-22 02:00:35 -05:00 committed by Jeff Carr
parent b34af98b7a
commit c102244930
4 changed files with 51 additions and 29 deletions

View File

@ -29,46 +29,51 @@ func main() {
log.Fatalf("Error unmarshaling log file %s: %v", filename, err) 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() { 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")
// Iterate through the entries within this named chat group.
for _, entry := range chat.GetEntries() {
author := entry.GetFrom().String()
// Handle content: prefer content_file, fallback to content. // Handle content: prefer content_file, fallback to content.
var content string var content string
if contentFile := chat.GetContentFile(); contentFile != "" { if contentFile := entry.GetContentFile(); contentFile != "" {
// Construct the full path relative to the log file's directory.
logDir := filepath.Dir(filename) logDir := filepath.Dir(filename)
contentPath := filepath.Join(logDir, contentFile) contentPath := filepath.Join(logDir, contentFile)
contentBytes, err := os.ReadFile(contentPath) contentBytes, err := os.ReadFile(contentPath)
if err != nil { if err != nil {
content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err) content = fmt.Sprintf("---\t ERROR: Could not read content file %s: %v ---", contentPath, err)
} else { } else {
content = string(contentBytes) content = string(contentBytes)
} }
} else { } else {
// Fallback for older log formats. content = entry.GetContent() // Fallback for older formats or inline content
content = chat.GetContent()
} }
// Print the conversational content first. // Print the conversational content first.
if content != "" { if content != "" {
// Trim trailing newlines for cleaner output.
fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content)) fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content))
} }
// Now, format and print any tool calls. // Now, format and print any tool calls.
for _, toolCall := range chat.GetToolCalls() { for _, toolCall := range entry.GetToolCalls() {
printToolCallBox(toolCall) printToolCallBox(toolCall)
} }
// Handle the new CodeSnippet field. // Handle the CodeSnippet field.
if snippets := chat.GetSnippets(); snippets != nil { if snippets := entry.GetSnippets(); snippets != nil {
logDir := filepath.Dir(filename) logDir := filepath.Dir(filename)
for _, snippet := range snippets { for _, snippet := range snippets {
printCodeSnippet(snippet, logDir) printCodeSnippet(snippet, logDir)
} }
} }
} }
}
} }
// printCodeSnippet formats a code snippet block by reading its content from a file. // printCodeSnippet formats a code snippet block by reading its content from a file.

View File

@ -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"
}
}

View File

@ -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.

View File

@ -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?