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:
parent
b34af98b7a
commit
c102244930
|
@ -29,40 +29,44 @@ 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")
|
||||
|
||||
// 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.
|
||||
var content string
|
||||
if contentFile := chat.GetContentFile(); contentFile != "" {
|
||||
// Construct the full path relative to the log file's directory.
|
||||
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("--- 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 {
|
||||
content = string(contentBytes)
|
||||
}
|
||||
} else {
|
||||
// Fallback for older log formats.
|
||||
content = chat.GetContent()
|
||||
content = entry.GetContent() // Fallback for older formats or inline content
|
||||
}
|
||||
|
||||
// Print the conversational content first.
|
||||
if content != "" {
|
||||
// Trim trailing newlines for cleaner output.
|
||||
fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content))
|
||||
}
|
||||
|
||||
// Now, format and print any tool calls.
|
||||
for _, toolCall := range chat.GetToolCalls() {
|
||||
for _, toolCall := range entry.GetToolCalls() {
|
||||
printToolCallBox(toolCall)
|
||||
}
|
||||
|
||||
// Handle the new CodeSnippet field.
|
||||
if snippets := chat.GetSnippets(); snippets != nil {
|
||||
// Handle the CodeSnippet field.
|
||||
if snippets := entry.GetSnippets(); snippets != nil {
|
||||
logDir := filepath.Dir(filename)
|
||||
for _, snippet := range snippets {
|
||||
printCodeSnippet(snippet, logDir)
|
||||
|
@ -70,6 +74,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printCodeSnippet formats a code snippet block by reading its content from a file.
|
||||
func printCodeSnippet(snippet *chatpb.CodeSnippet, logDir string) {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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.
|
|
@ -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?
|
Loading…
Reference in New Issue