commit ad39cfacbdc142c130ebef0b662ec007677e2acd Author: Jeff Carr Date: Thu Aug 21 10:52:40 2025 -0500 day1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa8a584 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.swp +go.mod +go.sum +/resources/*.so +/files/* +gemini diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd99b44 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +VERSION = $(shell git describe --tags) +BUILDTIME = $(shell date +%Y.%m.%d_%H%M) + +default: verbose + +vet: + @GO111MODULE=off go vet + @echo this go binary package builds okay + +verbose: goimports vet plugin + GO111MODULE=off go install -v -x \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +build: goimports vet plugin + GO111MODULE=off go build -v -x \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +install: goimports vet plugin + GO111MODULE=off go install \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +install-raw: goimports vet plugin + go install \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +plugin: + rm -f resources/*.so + # -cp ../../toolkits/gocui/gocui.so resources/ + +andlabs: clean install + gemini --gui gocui --gui-verbose --gui-file ../../toolkits/andlabs/andlabs.so + +gocui: install + gemini --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so >/tmp/gemini.log 2>&1 + +goimports: + reset + goimports -w *.go + @# // to globally reset paths: + @# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go + +clean: + -rm -f gemini go.* + go-mod-clean purge + +identify-protobuf: + autogenpb --identify ~/.gemini/gemini.pb diff --git a/argv.go b/argv.go new file mode 100644 index 0000000..38a01f6 --- /dev/null +++ b/argv.go @@ -0,0 +1,37 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +/* + this parses the command line arguements using alex flint's go-arg +*/ + +var argv args + +type args struct { + Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"` + Add *EmptyCmd `arg:"subcommand:add" help:"add a conversation"` + Force bool `arg:"--force" help:"try to strong arm things"` + Verbose bool `arg:"--verbose" help:"show more output"` + Bash bool `arg:"--bash" help:"generate bash completion"` + BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"` +} + +type EmptyCmd struct { +} + +type PlaybackCmd struct { + List *EmptyCmd `arg:"subcommand:list" help:"list memories"` + Force bool `arg:"--all" help:"try to strong arm things"` +} + +func (args) Version() string { + return ARGNAME + " " + VERSION + " Built on " + BUILDTIME +} + +func (a args) Description() string { + return ` +gemini -- interact with Googles' Gemini AI + ` +} diff --git a/argvAutoshell.go b/argvAutoshell.go new file mode 100644 index 0000000..a1a426f --- /dev/null +++ b/argvAutoshell.go @@ -0,0 +1,122 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "os" +) + +/* + handles shell autocomplete +*/ + +// used for shell auto completion +// var ARGNAME string = "forge" // todo: get this from $0 ? + +func deleteMatch() { + // f := forgedb.InitSimple() + fmt.Println("go.wit.com/lib/gui/repostatus todo: need to do this") +} + +func (args) doBashAuto() { + argv.doBashHelp() + switch argv.BashAuto[0] { + case "playback": + fmt.Println("list --force") + case "clean": + fmt.Println("user devel master") + default: + if argv.BashAuto[0] == ARGNAME { + // list the subcommands here + fmt.Println("playback add") + } + } + os.Exit(0) +} + +// prints help to STDERR // TODO: move everything below this to go-args +func (args) doBashHelp() { + if argv.BashAuto[1] != "''" { + // if this is not blank, then the user has typed something + return + } + if argv.BashAuto[0] != ARGNAME { + // if this is not the name of the command, the user already started doing something + return + } + if argv.BashAuto[0] == ARGNAME { + me.pp.WriteHelp(os.Stderr) + return + } + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "hello world") + fmt.Fprintln(os.Stderr, "") +} + +/* +// complete -F forge --bash forge +func (args) doBash() { + fmt.Println("# add this in your bashrc:") + fmt.Println("") + fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash") + fmt.Println("#") + fmt.Println("# todo: can this output work/parse with:") + fmt.Println("# complete -C `" + ARGNAME + " --bash` " + ARGNAME) + fmt.Println("") + fmt.Println("_" + ARGNAME + "_complete()") + fmt.Println("{") + fmt.Println(" # sets local to this func vars") + fmt.Println(" local cur prev all") + fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}") + fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}") + fmt.Println(" all=${COMP_WORDS[@]}") + fmt.Println("") + fmt.Println(" # this is where we generate the go-arg output") + fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)") + fmt.Println("") + fmt.Println(" # this compares the command line input from the user") + fmt.Println(" # to whatever strings we output") + fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS") + fmt.Println(" return 0") + fmt.Println("}") + fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME) + fmt.Println("") + fmt.Println("# copy and paste the above into your bash shell should work") + os.Exit(0) +} +*/ + +// complete -F forge --bash forge +func (args) doBash() { + fmt.Println("# add this in your bashrc:") + fmt.Println("") + fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash") + fmt.Println("#") + fmt.Println("# Put the below in the file: ~/.local/share/bash-completion/completions/" + ARGNAME) + fmt.Println("#") + fmt.Println("# todo: make this output work/parse with:") + fmt.Println("# complete -C " + ARGNAME + " --bash go") + fmt.Println("") + fmt.Println("_" + ARGNAME + "_complete()") + fmt.Println("{") + fmt.Println(" # sets local to this func vars") + fmt.Println(" local cur prev all") + fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}") + fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}") + fmt.Println(" all=${COMP_WORDS[@]}") + fmt.Println("") + fmt.Println(" # this is where we generate the go-arg output") + fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)") + fmt.Println("") + fmt.Println(" # this compares the command line input from the user") + fmt.Println(" # to whatever strings we output") + fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS") + fmt.Println(" return 0") + fmt.Println("}") + fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME) + fmt.Println("") + fmt.Println("# copy and paste the above into your bash shell should work") + os.Exit(0) +} diff --git a/control b/control new file mode 100644 index 0000000..35118f2 --- /dev/null +++ b/control @@ -0,0 +1,9 @@ +Package: gemini +Maintainer: Jeff Carr +Depends: go-gui-toolkits +Build-Depends: golang, protoc-gen-go, autogenpb, go-mod-clean +Description: interact with Google's Gemini AI + Goals: + Save all interactions in a protobuf + Have a Terminal UI, Console UI and GUI (GTK) + Can "restart" from where you left off diff --git a/exit.go b/exit.go new file mode 100644 index 0000000..8acd5e8 --- /dev/null +++ b/exit.go @@ -0,0 +1,22 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "os" + + "go.wit.com/log" +) + +func okExit(thing string) { + if thing != "" { + log.Info("gemini exit:", thing, "ok") + } + os.Exit(0) +} + +func badExit(err error) { + log.Info("gemini failed: ", err) + os.Exit(-1) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..e6150f9 --- /dev/null +++ b/main.go @@ -0,0 +1,71 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +// An app to submit patches for the 30 GO GUI repos + +import ( + "embed" + "os" + "strings" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/gui" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +// this optionally can store the GUI plugins +// +//go:embed resources/* +var resources embed.FS + +// used for shell auto completion +var ARGNAME string = "gemini" + +// using this for now. triggers config save +var configSave bool + +func getVersion(repo *gitpb.Repo, name string) string { + cmd := []string{"git", "describe", "--tags", "--always", name} + result, _ := repo.RunQuiet(cmd) + output := strings.Join(result.Stdout, "\n") + log.Info("cmd =", cmd, output) + + return strings.TrimSpace(output) +} + +func main() { + me = new(mainType) + gui.InitArg() + me.pp = arg.MustParse(&argv) + + if argv.Bash { + argv.doBash() + os.Exit(0) + } + if len(argv.BashAuto) != 0 { + argv.doBashAuto() + os.Exit(0) + } + + if argv.Playback != nil { + log.Info("do playback here") + okExit("") + } + + if argv.Add != nil { + log.Info("add new conversation to protobuf") + okExit("") + } + + // if opening the GUI, always check git for dirty repos + log.Info("open the gui here") + // doGui() + okExit("") +} diff --git a/resources/forge.text b/resources/forge.text new file mode 100644 index 0000000..947b5fb --- /dev/null +++ b/resources/forge.text @@ -0,0 +1,22 @@ +# this file is intended to be used to customize settings on what +# git repos you have write access to. That is, where you can run 'git push' +# +# add entries to this using 'forge config' + +ForgeConfigs: { + goPath: "go.wit.com" + writable: true + directory: true +} +repos: { + goPath: "go.wit.com/apps/zookeeper" + debName: "zookeeper-go" +} +xterm: "xterm" +xtermArgv: "-bg" +xtermArgv: "black" +xtermArgv: "-fg" +xtermArgv: "white" +xtermArgv: "-geometry" +xtermArgv: "140x32" +xtermArgv: "-e" diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..6f7efa0 --- /dev/null +++ b/structs.go @@ -0,0 +1,16 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "go.wit.com/dev/alexflint/arg" +) + +var me *mainType + +// this app's variables +type mainType struct { + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + // myGui *gui.Node // the gui toolkit handle +}