s/gemini/regex/

This commit is contained in:
Jeff Carr 2025-08-24 01:12:21 -05:00
parent 443e5db5ae
commit e83b6361c1
4 changed files with 27 additions and 27 deletions

View File

@ -15,7 +15,7 @@ message Table { // `autogenpb:nomute
enum Who { enum Who {
NOONE = 0; NOONE = 0;
GEMINI = 1; REGEX = 1;
USER = 2; USER = 2;
} }

View File

@ -14,12 +14,12 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
// write to ~/.config/gemini/ unless ENV{GEMINI_HOME} is set // write to ~/.config/regex/ unless ENV{REGEX_HOME} is set
func (all *Chats) ConfigSave() error { func (all *Chats) ConfigSave() error {
if os.Getenv("GEMINI_HOME") == "" { if os.Getenv("REGEX_HOME") == "" {
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/gemini") fullpath := filepath.Join(homeDir, ".config/regex")
os.Setenv("GEMINI_HOME", fullpath) os.Setenv("REGEX_HOME", fullpath)
} }
if all == nil { if all == nil {
log.Warn("chatpb all == nil") log.Warn("chatpb all == nil")
@ -52,7 +52,7 @@ func (all *Chats) ConfigSave() error {
data, err = cleanChats.Marshal() // Retry with the clean object data, err = cleanChats.Marshal() // Retry with the clean object
if err == nil { if err == nil {
log.Info("chatpb.ConfigSave() pb.Marshal() worked after validation len", len(cleanChats.Chats), "chats") log.Info("chatpb.ConfigSave() pb.Marshal() worked after validation len", len(cleanChats.Chats), "chats")
configWrite("gemini.pb", data) configWrite("regex.pb", data)
return nil return nil
} }
} }
@ -60,12 +60,12 @@ func (all *Chats) ConfigSave() error {
} }
// --- Backup Logic --- // --- Backup Logic ---
filename := filepath.Join(os.Getenv("GEMINI_HOME"), "gemini.pb") filename := filepath.Join(os.Getenv("REGEX_HOME"), "regex.pb")
if _, err := os.Stat(filename); err == nil { if _, err := os.Stat(filename); err == nil {
// File exists, so back it up. // File exists, so back it up.
dir := filepath.Dir(filename) dir := filepath.Dir(filename)
timestamp := time.Now().Format("20060102-150405") timestamp := time.Now().Format("20060102-150405")
backupFilename := fmt.Sprintf("gemini.%s.pb", timestamp) backupFilename := fmt.Sprintf("regex.%s.pb", timestamp)
backupPath := filepath.Join(dir, backupFilename) backupPath := filepath.Join(dir, backupFilename)
if err := os.Rename(filename, backupPath); err != nil { if err := os.Rename(filename, backupPath); err != nil {
log.Warn("Could not backup config file:", err) log.Warn("Could not backup config file:", err)
@ -73,11 +73,11 @@ func (all *Chats) ConfigSave() error {
} }
// --- End Backup Logic --- // --- End Backup Logic ---
if err := configWrite("gemini.pb", data); err != nil { if err := configWrite("regex.pb", data); err != nil {
log.Infof("chatpb.ConfigSave() failed len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data)) log.Infof("chatpb.ConfigSave() failed len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data))
return err return err
} }
configWrite("gemini.text", []byte(cleanChats.FormatTEXT())) configWrite("regex.text", []byte(cleanChats.FormatTEXT()))
log.Infof("chatpb.ConfigSave() worked len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data)) log.Infof("chatpb.ConfigSave() worked len(Chats)=%d bytes=%d", len(cleanChats.Chats), len(data))
return nil return nil
} }
@ -96,29 +96,29 @@ func (all *Chats) tryValidate() error {
return nil return nil
} }
// load the gemini.pb file. I shouldn't really matter if this // load the regex.pb file. I shouldn't really matter if this
// fails. the file should be autogenerated. This is used // fails. the file should be autogenerated. This is used
// locally just for speed // locally just for speed
func (all *Chats) ConfigLoad() error { func (all *Chats) ConfigLoad() error {
if os.Getenv("GEMINI_HOME") == "" { if os.Getenv("REGEX_HOME") == "" {
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/gemini") fullpath := filepath.Join(homeDir, ".config/regex")
os.Setenv("GEMINI_HOME", fullpath) os.Setenv("REGEX_HOME", fullpath)
} }
var data []byte var data []byte
var err error var err error
cfgname := filepath.Join(os.Getenv("GEMINI_HOME"), "gemini.pb") cfgname := filepath.Join(os.Getenv("REGEX_HOME"), "regex.pb")
if data, err = loadFile(cfgname); err != nil { if data, err = loadFile(cfgname); err != nil {
// something went wrong loading the file // something went wrong loading the file
// all.sampleConfig() // causes nil panic // all.sampleConfig() // causes nil panic
return err return err
} }
// this means the gemini.pb file exists and was read // this means the regex.pb file exists and was read
if len(data) == 0 { if len(data) == 0 {
// todo: add default data here since it's blank? // might cause nil panic? // todo: add default data here since it's blank? // might cause nil panic?
all.AddGeminiComment("I like astronomy") all.AddRegexComment("I like astronomy")
log.Info(errors.New("chatpb.ConfigLoad() gemini.pb is empty")) log.Info(errors.New("chatpb.ConfigLoad() regex.pb is empty"))
return nil return nil
} }
err = all.Unmarshal(data) err = all.Unmarshal(data)
@ -149,7 +149,7 @@ func loadFile(fullname string) ([]byte, error) {
data, err := os.ReadFile(fullname) data, err := os.ReadFile(fullname)
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
// if file does not exist, just return nil. this // if file does not exist, just return nil. this
// will cause ConfigLoad() to try the next config file like "gemini.text" // will cause ConfigLoad() to try the next config file like "regex.text"
// because the user might want to edit the .config by hand // because the user might want to edit the .config by hand
return nil, nil return nil, nil
} }
@ -161,7 +161,7 @@ func loadFile(fullname string) ([]byte, error) {
} }
func configWrite(filename string, data []byte) error { func configWrite(filename string, data []byte) error {
fullname := filepath.Join(os.Getenv("GEMINI_HOME"), filename) fullname := filepath.Join(os.Getenv("REGEX_HOME"), filename)
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
defer cfgfile.Close() defer cfgfile.Close()
@ -169,11 +169,11 @@ func configWrite(filename string, data []byte) error {
log.Warn("open config file :", err) log.Warn("open config file :", err)
return err return err
} }
if filename == "gemini.text" { if filename == "regex.text" {
// add header // add header
cfgfile.Write([]byte("# this file is automatically re-generated from gemini.pb, however,\n")) cfgfile.Write([]byte("# this file is automatically re-generated from regex.pb, however,\n"))
cfgfile.Write([]byte("# if you want to edit it by hand, you can:\n")) cfgfile.Write([]byte("# if you want to edit it by hand, you can:\n"))
cfgfile.Write([]byte("# stop gemini; remove gemini.pb; edit gemini.text; start gemini\n")) cfgfile.Write([]byte("# stop regex; remove regex.pb; edit regex.text; start regex\n"))
cfgfile.Write([]byte("# this will cause the default behavior to fallback to parsing this file for the config\n")) cfgfile.Write([]byte("# this will cause the default behavior to fallback to parsing this file for the config\n"))
cfgfile.Write([]byte("\n")) cfgfile.Write([]byte("\n"))
cfgfile.Write([]byte("# this file is intended to be used to customize settings on what\n")) cfgfile.Write([]byte("# this file is intended to be used to customize settings on what\n"))

View File

@ -7,10 +7,10 @@ import (
func ExampleChat() *Chats { func ExampleChat() *Chats {
conversation := NewChats() conversation := NewChats()
conversation.AddGeminiComment("funny") conversation.AddRegexComment("funny")
/* /*
gchat := conversation.AddGeminiComment("funny") gchat := conversation.AddRegexComment("funny")
snip := new(CodeSnippet) snip := new(CodeSnippet)
snip.Filename = "log/snip1.txt" snip.Filename = "log/snip1.txt"
gchat.Snippets = append(gchat.Snippets, snip) gchat.Snippets = append(gchat.Snippets, snip)
@ -18,7 +18,7 @@ func ExampleChat() *Chats {
conversation.AddUserComment("yes") conversation.AddUserComment("yes")
conversation.AddGeminiComment("I like astronomy") conversation.AddRegexComment("I like astronomy")
dump := conversation.FormatTEXT() dump := conversation.FormatTEXT()

View File

@ -9,7 +9,7 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
func (c *Chats) AddGeminiComment(s string) *ChatEntry { func (c *Chats) AddRegexComment(s string) *ChatEntry {
log.Info("FIX") log.Info("FIX")
return nil return nil
} }