summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCastor Gemini <[email protected]>2025-08-22 02:51:47 -0500
committerJeff Carr <[email protected]>2025-08-22 02:51:47 -0500
commitbffc301568d59d137fba657628eee3d19780e296 (patch)
tree66bbbf4cb571cb08f92b22e7b97fc3d37509f558
parent3d6f228b6e14d87795edf6bc0a8ec8930f34929f (diff)
refactor(gemini): Adapt app to new protobuf structure
- Update main.go and doPlayback.go to be compatible with the refactored 'Chat -> Entries' protobuf message format. - Remove the now-obsolete format_rich_log.go file. - The application now compiles successfully against the new chatpb library.
-rw-r--r--doPlayback.go2
-rw-r--r--format_rich_log.go147
-rw-r--r--main.go16
3 files changed, 9 insertions, 156 deletions
diff --git a/doPlayback.go b/doPlayback.go
index f39776c..0495ac0 100644
--- a/doPlayback.go
+++ b/doPlayback.go
@@ -12,7 +12,7 @@ func doPlayback() {
// Iterate through the top-level Chat messages, which are now named groups.
for _, chat := range me.chats.GetChats() {
-
+
// Get the number of entries in the chat.
entryCount := len(chat.GetEntries())
diff --git a/format_rich_log.go b/format_rich_log.go
deleted file mode 100644
index 09bea60..0000000
--- a/format_rich_log.go
+++ /dev/null
@@ -1,147 +0,0 @@
-package main
-
-import (
- "fmt"
- "os"
- "path/filepath"
- "strings"
-
- "go.wit.com/lib/protobuf/chatpb"
- "go.wit.com/log"
-)
-
-const termWidth = 120 // The target width for the formatted output boxes.
-
-func parseRichLog(filename string) *chatpb.Chats {
- data, err := os.ReadFile(filename)
- if err != nil {
- log.Fatalf("Error reading file %s: %v", filename, err)
- }
-
- logData, err := chatpb.UnmarshalChatsTEXT(data)
- if err != nil {
- log.Fatalf("Error unmarshaling log file %s: %v", filename, err)
- }
-
- for _, chat := range logData.GetChats() {
- // 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)
-
- contentBytes, err := os.ReadFile(contentPath)
- if err != nil {
- content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err)
- } else {
- content = string(contentBytes)
- }
- } else {
- // Fallback for older log formats.
- content = chat.GetContent()
- }
- chat.Content = content
- }
-
- return logData
-}
-
-func formatRichLog(filename string) *chatpb.Chats {
- data, err := os.ReadFile(filename)
- if err != nil {
- log.Fatalf("Error reading file %s: %v", filename, err)
- }
-
- logData, err := chatpb.UnmarshalChatsTEXT(data)
- if err != nil {
- log.Fatalf("Error unmarshaling log file %s: %v", filename, err)
- }
-
- for _, chat := range logData.GetChats() {
- author := chat.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.
- 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)
- } else {
- content = string(contentBytes)
- }
- } 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))
- }
-
- // Now, format and print any tool calls.
- for _, toolCall := range chat.GetToolCalls() {
- printToolCallBox(toolCall)
- }
- }
-
- return logData
-}
-
-// printToolCallBox handles the decorative formatting for a single tool call.
-func printToolCallBox(tc *chatpb.ToolCall) {
- boxWidth := termWidth - 2 // Account for the side borders.
-
- // --- Top Border ---
- fmt.Printf(" ╭%s╮\n", strings.Repeat("─", boxWidth))
-
- // --- Header Line ---
- header := fmt.Sprintf(" ✔ %s %s (%s)", tc.GetName(), tc.GetInput(), tc.GetDescription())
- printWrappedLine(header, boxWidth)
- printEmptyLine(boxWidth)
-
- // --- Stdout ---
- if stdout := tc.GetOutputStdout(); stdout != "" {
- for _, line := range strings.Split(stdout, "\n") {
- printWrappedLine(" "+line, boxWidth)
- }
- }
-
- // --- Stderr ---
- if stderr := tc.GetOutputStderr(); stderr != "" {
- for _, line := range strings.Split(stderr, "\n") {
- printWrappedLine(" "+line, boxWidth)
- }
- }
-
- printEmptyLine(boxWidth)
-
- // --- Bottom Border ---
- fmt.Printf(" ╰%s╯\n", strings.Repeat("─", boxWidth))
-}
-
-// printWrappedLine prints a line of text, wrapping it if it's too long.
-func printWrappedLine(text string, width int) {
- if len(text) == 0 {
- printEmptyLine(width)
- return
- }
-
- // Simple wrapping logic.
- for len(text) > width {
- fmt.Printf(" │ %-*s │\n", width, text[:width])
- text = text[width:]
- }
- fmt.Printf(" │ %-*s │\n", width, text)
-}
-
-// printEmptyLine prints a blank line within the box.
-func printEmptyLine(width int) {
- fmt.Printf(" │ %*s │\n", width, "")
-}
diff --git a/main.go b/main.go
index 8312610..3f1c795 100644
--- a/main.go
+++ b/main.go
@@ -71,10 +71,7 @@ func main() {
}
if argv.Playback != nil {
- log.Info("do playback here")
doPlayback()
- // pb := formatRichLog("log/2025-08-20-final.text")
- // pb.ConfigSave()
okExit("")
}
@@ -90,14 +87,17 @@ func main() {
func verifyUuids(chats *chatpb.Chats) bool {
var changed bool
-
- all := chats.SortByUuid()
- for all.Scan() {
- chat := all.Next()
- if chat.Uuid == "" {
+ for _, chat := range chats.GetChats() {
+ if chat.GetUuid() == "" {
chat.Uuid = uuid.New().String()
changed = true
}
+ for _, entry := range chat.GetEntries() {
+ if entry.GetUuid() == "" {
+ entry.Uuid = uuid.New().String()
+ changed = true
+ }
+ }
}
return changed
}