make an --add <filename> option
This commit is contained in:
parent
b221e7a95c
commit
a10b75d453
2
argv.go
2
argv.go
|
@ -10,7 +10,7 @@ package main
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
Add *EmptyCmd `arg:"subcommand:add" help:"add a conversation"`
|
Add string `arg:"--add" help:"add a new chat"`
|
||||||
Format *EmptyCmd `arg:"subcommand:format" help:"add a conversation"`
|
Format *EmptyCmd `arg:"subcommand:format" help:"add a conversation"`
|
||||||
Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"`
|
Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"`
|
||||||
Force bool `arg:"--force" help:"try to strong arm things"`
|
Force bool `arg:"--force" help:"try to strong arm things"`
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (args) doBashAuto() {
|
||||||
default:
|
default:
|
||||||
if argv.BashAuto[0] == ARGNAME {
|
if argv.BashAuto[0] == ARGNAME {
|
||||||
// list the subcommands here
|
// list the subcommands here
|
||||||
fmt.Println("add format playback")
|
fmt.Println("--add format playback")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -12,6 +12,41 @@ import (
|
||||||
|
|
||||||
const termWidth = 120 // The target width for the formatted output boxes.
|
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 {
|
func formatRichLog(filename string) *chatpb.Chats {
|
||||||
data, err := os.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
40
main.go
40
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/protobuf/chatpb"
|
"go.wit.com/lib/protobuf/chatpb"
|
||||||
|
@ -55,8 +56,29 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Add != nil {
|
me.chats = chatpb.NewChats()
|
||||||
log.Info("add new conversation to protobuf")
|
if err := me.chats.ConfigLoad(); err != nil {
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
|
if verifyUuids(me.chats) {
|
||||||
|
me.chats.ConfigSave()
|
||||||
|
}
|
||||||
|
|
||||||
|
if argv.Add != "" {
|
||||||
|
log.Info("add new conversation to protobuf", argv.Add)
|
||||||
|
pb := parseRichLog(argv.Add)
|
||||||
|
verifyUuids(pb)
|
||||||
|
all := pb.SortByUuid()
|
||||||
|
for all.Scan() {
|
||||||
|
chat := all.Next()
|
||||||
|
log.Info("NEW CHAT", chat.From, chat.Uuid)
|
||||||
|
if test := me.chats.FindByContentFile(chat.ContentFile); test != nil {
|
||||||
|
log.Info("NOT NEW CHAT", test.ContentFile)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
me.chats.AppendByUuid(chat)
|
||||||
|
}
|
||||||
|
pb.ConfigSave()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,3 +98,17 @@ func main() {
|
||||||
// doGui()
|
// doGui()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifyUuids(chats *chatpb.Chats) bool {
|
||||||
|
var changed bool
|
||||||
|
|
||||||
|
all := chats.SortByUuid()
|
||||||
|
for all.Scan() {
|
||||||
|
chat := all.Next()
|
||||||
|
if chat.Uuid == "" {
|
||||||
|
chat.Uuid = uuid.New().String()
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
|
@ -5,12 +5,15 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/gui"
|
||||||
|
"go.wit.com/lib/protobuf/chatpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var me *mainType
|
var me *mainType
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type mainType struct {
|
type mainType struct {
|
||||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||||
// myGui *gui.Node // the gui toolkit handle
|
chats *chatpb.Chats // all our prior conversations with gemini
|
||||||
|
myGui *gui.Node // the gui toolkit handle
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue