Enha (cli): -msg -continue flags

This commit is contained in:
Grail Finder
2026-03-16 07:52:55 +03:00
parent 7f8bbefb05
commit 7c8697f48e

43
main.go
View File

@@ -30,18 +30,21 @@ var (
focusSwitcher = map[tview.Primitive]tview.Primitive{} focusSwitcher = map[tview.Primitive]tview.Primitive{}
app *tview.Application app *tview.Application
cliCardPath string cliCardPath string
cliContinue bool
cliMsg string
) )
func main() { func main() {
flag.BoolVar(&cfg.CLIMode, "cli", false, "Run in CLI mode without TUI") flag.BoolVar(&cfg.CLIMode, "cli", false, "Run in CLI mode without TUI")
flag.BoolVar(&cfg.ToolUse, "tools", true, "run with tools")
flag.StringVar(&cliCardPath, "card", "", "Path to syscard JSON file") flag.StringVar(&cliCardPath, "card", "", "Path to syscard JSON file")
flag.BoolVar(&cliContinue, "continue", false, "Continue from last chat (by agent or card)")
flag.StringVar(&cliMsg, "msg", "", "Send message and exit (one-shot mode)")
flag.Parse() flag.Parse()
if cfg.CLIMode { if cfg.CLIMode {
runCLIMode() runCLIMode()
return return
} }
pages.AddPage("main", flex, true, true) pages.AddPage("main", flex, true, true)
if err := app.SetRoot(pages, if err := app.SetRoot(pages,
true).EnableMouse(cfg.EnableMouse).EnablePaste(true).Run(); err != nil { true).EnableMouse(cfg.EnableMouse).EnablePaste(true).Run(); err != nil {
@@ -53,7 +56,6 @@ func main() {
func runCLIMode() { func runCLIMode() {
outputHandler = &CLIOutputHandler{} outputHandler = &CLIOutputHandler{}
cliRespDone = make(chan bool, 1) cliRespDone = make(chan bool, 1)
if cliCardPath != "" { if cliCardPath != "" {
card, err := pngmeta.ReadCardJson(cliCardPath) card, err := pngmeta.ReadCardJson(cliCardPath)
if err != nil { if err != nil {
@@ -66,16 +68,38 @@ func runCLIMode() {
charToStart(card.Role, false) charToStart(card.Role, false)
fmt.Printf("Loaded syscard: %s (%s)\n", card.Role, card.FilePath) fmt.Printf("Loaded syscard: %s (%s)\n", card.Role, card.FilePath)
} }
if cliContinue {
if cliCardPath != "" {
history, err := loadAgentsLastChat(cfg.AssistantRole)
if err != nil {
fmt.Printf("No previous chat found for %s, starting new chat\n", cfg.AssistantRole)
startNewCLIChat() startNewCLIChat()
} else {
chatBody.Messages = history
fmt.Printf("Continued chat: %s\n", activeChatName)
}
} else {
chatBody.Messages = loadOldChatOrGetNew()
fmt.Printf("Continued chat: %s\n", activeChatName)
}
} else {
startNewCLIChat()
}
printCLIWelcome() printCLIWelcome()
go func() { go func() {
<-ctx.Done() <-ctx.Done()
os.Exit(0) os.Exit(0)
}() }()
if cliMsg != "" {
persona := cfg.UserRole
if cfg.WriteNextMsgAs != "" {
persona = cfg.WriteNextMsgAs
}
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: cliMsg}
<-cliRespDone
fmt.Println()
return
}
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
for { for {
fmt.Print("> ") fmt.Print("> ")
@@ -86,7 +110,6 @@ func runCLIMode() {
if msg == "" { if msg == "" {
continue continue
} }
if strings.HasPrefix(msg, "/") { if strings.HasPrefix(msg, "/") {
if !handleCLICommand(msg) { if !handleCLICommand(msg) {
return return
@@ -94,7 +117,6 @@ func runCLIMode() {
fmt.Println() fmt.Println()
continue continue
} }
persona := cfg.UserRole persona := cfg.UserRole
if cfg.WriteNextMsgAs != "" { if cfg.WriteNextMsgAs != "" {
persona = cfg.WriteNextMsgAs persona = cfg.WriteNextMsgAs
@@ -196,7 +218,8 @@ func handleCLICommand(msg string) bool {
fmt.Printf("Loaded chat: %s\n", name) fmt.Printf("Loaded chat: %s\n", name)
case "/model", "/m": case "/model", "/m":
if len(args) == 0 { if len(args) == 0 {
fmt.Printf("Current model: %s\n", chatBody.Model) // fmt.Printf("Current model: %s\n", chatBody.Model)
fmt.Println("Models: ", LocalModels)
return true return true
} }
chatBody.Model = args[0] chatBody.Model = args[0]