feat(gemini): add file import capability

This commit introduces the `doImport` function, which allows importing
the content of a file directly into the "auto" chat session.

The imported content is added as a `ChatEntry` from GEMINI, structured
as a `ToolCall` with the name "Shell" and the file content as the input.
This allows external command outputs to be seamlessly integrated into
the chat history for context.
This commit is contained in:
Castor Gemini 2025-08-22 11:47:00 -05:00 committed by Jeff Carr
parent 7646310dd4
commit 40243de35b
3 changed files with 71 additions and 9 deletions

19
argv.go
View File

@ -10,15 +10,16 @@ package main
var argv args
type args struct {
Add string `arg:"--add" help:"add a new chat"`
Format *EmptyCmd `arg:"subcommand:format" help:"add a conversation"`
Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"`
Output string `arg:"--output" help:"should get a string from gemini-cli"`
Input string `arg:"--input" help:"should get a string from gemini-cli"`
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"`
Add string `arg:"--add" help:"add a new chat"`
Format *EmptyCmd `arg:"subcommand:format" help:"add a conversation"`
Playback *PlaybackCmd `arg:"subcommand:playback" help:"dump your prior conversations to the terminal'"`
Output string `arg:"--output" help:"should get a string from gemini-cli"`
Input string `arg:"--input" help:"should get a string from gemini-cli"`
ImportFile string `arg:"--import" help:"import a file from gemini-cli"`
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 {

56
doImport.go Normal file
View File

@ -0,0 +1,56 @@
package main
import (
"io/ioutil"
"time"
"go.wit.com/lib/protobuf/chatpb"
"go.wit.com/log"
"google.golang.org/protobuf/types/known/timestamppb"
)
func doImport(filename string) {
content, err := ioutil.ReadFile(filename)
if err != nil {
log.Warn("Error reading import file:", err)
return
}
s := string(content)
// Load the existing chats.
all := chatpb.NewChats()
if err := all.ConfigLoad(); err != nil {
log.Warn("Error loading config, can't add to auto chat:", err)
return
}
// Find the "auto" chat.
var autoChat *chatpb.Chat
for _, chat := range all.GetChats() {
if chat.GetChatName() == "auto" {
autoChat = chat
break
}
}
// If the "auto" chat is found, add the new entry.
if autoChat != nil {
newEntry := &chatpb.ChatEntry{
From: chatpb.Who_GEMINI,
Ctime: timestamppb.New(time.Now()),
ToolCalls: []*chatpb.ToolCall{
{
Name: "Shell",
Input: s,
},
},
}
autoChat.Entries = append(autoChat.Entries, newEntry)
if err := all.ConfigSave(); err != nil {
log.Warn("Error saving config after adding to auto chat:", err)
} else {
log.Info("Added new entry to 'auto' chat.")
}
}
}

View File

@ -63,6 +63,11 @@ func main() {
okExit("")
}
if argv.ImportFile != "" {
doImport(argv.ImportFile)
okExit("")
}
if argv.Add != "" {
newChats, err := addFile(argv.Add)
if err != nil {