working on processing JSON files
This commit is contained in:
parent
26d674c800
commit
8220d1817c
2
Makefile
2
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
|
||||
|
|
1
argv.go
1
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"`
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
2
doGui.go
2
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)
|
||||
}
|
||||
}
|
||||
|
|
23
main.go
23
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
|
||||
|
|
Loading…
Reference in New Issue