summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--argv.go1
-rw-r--r--argvAutoshell.go4
-rw-r--r--doClean.go87
-rw-r--r--doGui.go2
-rw-r--r--main.go23
6 files changed, 110 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index a240a6a..c1629ba 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
default: install
- regex playback
+ regex clean
vet:
@GO111MODULE=off go vet
diff --git a/argv.go b/argv.go
index 54b4900..58a94e0 100644
--- a/argv.go
+++ b/argv.go
@@ -16,6 +16,7 @@ type args struct {
Interact *EmptyCmd `arg:"subcommand:interact" help:"open env EDITOR"`
Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"`
NewChat *PlaybackCmd `arg:"subcommand:newchat" help:"used by gemini-cli on startup"`
+ Clean *EmptyCmd `arg:"subcommand:clean" help:"cleanup the files in /tmp"`
Stats string `arg:"--stats" help:"add stats to a chat"`
Force bool `arg:"--force" help:"try to strong arm things"`
Verbose bool `arg:"--verbose" help:"show more output"`
diff --git a/argvAutoshell.go b/argvAutoshell.go
index f6fcee7..250da3f 100644
--- a/argvAutoshell.go
+++ b/argvAutoshell.go
@@ -26,11 +26,11 @@ func (args) doBashAuto() {
case "playback":
fmt.Println("long --uuid purge last submit")
case "clean":
- fmt.Println("user devel master")
+ fmt.Println("")
default:
if argv.BashAuto[0] == ARGNAME {
// list the subcommands here
- fmt.Println("--json interact playback")
+ fmt.Println("--json interact playback clean")
}
}
os.Exit(0)
diff --git a/doClean.go b/doClean.go
new file mode 100644
index 0000000..e4c9783
--- /dev/null
+++ b/doClean.go
@@ -0,0 +1,87 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func doClean() {
+ log.Info("find all files")
+ scanTmp()
+}
+
+func scanTmp() {
+ var count int
+ filepath.WalkDir("/tmp", func(path string, d os.DirEntry, err error) error {
+ if err != nil {
+ // Handle possible errors, like permission issues
+ // fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
+ // ignore all these problems
+ return err
+ }
+
+ /*
+ if d.IsDir() {
+ // log.Info("path is dir", path)
+ return nil
+ }
+ */
+
+ _, fname := filepath.Split(path)
+ if !strings.HasPrefix(fname, "regex.") {
+ return nil
+ }
+ if count > 5 {
+ return log.Errorf("count exceeded")
+ }
+ if strings.HasPrefix(fname, "regex.gemini-api-response") {
+ // log.Info("response file:", fname)
+ return nil
+ }
+ if strings.Contains(fname, "gemini-api-request") {
+ // log.Info("response file:", fname)
+ if err := cleanGeminiFile(path); err == nil {
+ count += 1
+ return nil
+ } else {
+ return nil
+ }
+ }
+ if strings.HasSuffix(fname, ".stats") {
+ cleanStatsFile(path)
+ return nil
+ }
+ log.Info("check file:", path)
+ return nil
+ })
+}
+
+func cleanStatsFile(fullname string) {
+ log.Info("stats file", fullname)
+}
+
+func cleanGeminiFile(fullname string) error {
+ _, fname := filepath.Split(fullname)
+ if !strings.HasSuffix(fname, ".json") {
+ return log.Errorf("not really gemini-api-request .json")
+ }
+ parts := strings.Split(fname, ".")
+ if len(parts) == 5 {
+ if parts[2] != "gemini-api-request" {
+ return log.Errorf("not really gemini-api-request")
+ }
+ }
+ uuid := parts[1]
+ for _, chat := range me.chats.GetChats() {
+ // log.Info(i, chat.Uuid)
+ if chat.Uuid == uuid {
+ log.Info("found uuid", uuid)
+ return nil
+ }
+ }
+ log.Info("gemini JSON file uuid not found", uuid)
+ return log.Errorf("gemini JSON file uuid %s not found", uuid)
+}
diff --git a/doGui.go b/doGui.go
index 4be20d2..8db34eb 100644
--- a/doGui.go
+++ b/doGui.go
@@ -20,7 +20,7 @@ import (
func debug() {
time.Sleep(2 * time.Second)
for {
- log.Printf("idle loop() could check for things here")
+ log.Info("idle loop() todo: could check for things here")
time.Sleep(90 * time.Second)
}
}
diff --git a/main.go b/main.go
index 709fb29..3d731d0 100644
--- a/main.go
+++ b/main.go
@@ -32,8 +32,7 @@ var ARGNAME string = "regex"
var configSave bool
func main() {
- // f, _ := os.OpenFile("/tmp/regex.secret.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- // log.CaptureMode(f)
+ var err error
me = new(mainType)
gui.InitArg()
me.pp = arg.MustParse(&argv)
@@ -58,11 +57,20 @@ func main() {
me.chats.ConfigSave()
}
- err := doConnect()
- if err != nil {
- badExit(err)
+ // Get the last chat
+ numChats := len(me.chats.GetChats())
+ if numChats > 0 {
+ me.lastChat = me.chats.GetChats()[numChats-1]
+ log.Printf("The current Gemini API session is UUID: %s\n", me.lastChat.GetUuid())
}
+ /*
+ err := doConnect()
+ if err != nil {
+ badExit(err)
+ }
+ */
+
if argv.JsonFile != "" {
doJSON()
okExit("")
@@ -98,6 +106,11 @@ func main() {
okExit("")
}
+ if argv.Clean != nil {
+ doClean()
+ okExit("")
+ }
+
doGui()
// by default, start interacting with gemini-cli