From a28e8ef9e250ace5c9624393da308c189c0839f6 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Wed, 21 Jan 2026 21:01:01 +0300 Subject: Enha: charlist in cards --- bot.go | 1 - helpfuncs.go | 25 ++++++++++++++++++++++++- models/card.go | 18 ++++++++++-------- sysprompts/alice_bob_carl.json | 1 + tui.go | 7 +++---- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/bot.go b/bot.go index 2c59f07..112af07 100644 --- a/bot.go +++ b/bot.go @@ -1063,7 +1063,6 @@ func addNewChat(chatName string) { func applyCharCard(cc *models.CharCard) { cfg.AssistantRole = cc.Role - // FIXME: remove history, err := loadAgentsLastChat(cfg.AssistantRole) if err != nil { // too much action for err != nil; loadAgentsLastChat needs to be split up diff --git a/helpfuncs.go b/helpfuncs.go index ccb5858..f74cd13 100644 --- a/helpfuncs.go +++ b/helpfuncs.go @@ -164,7 +164,7 @@ func setLogLevel(sl string) { } func listRolesWithUser() []string { - roles := chatBody.ListRoles() + roles := listChatRoles() // Remove user role if it exists in the list (to avoid duplicates and ensure it's at position 0) filteredRoles := make([]string, 0, len(roles)) for _, role := range roles { @@ -250,3 +250,26 @@ func randString(n int) string { } return string(b) } + +// set of roles within card definition and mention in chat history +func listChatRoles() []string { + currentChat, ok := chatMap[activeChatName] + cbc := chatBody.ListRoles() + if !ok { + return cbc + } + currentCard, ok := sysMap[currentChat.Agent] + if !ok { + // log error + logger.Warn("failed to find current card in sysMap", "agent", currentChat.Agent, "sysMap", sysMap) + return cbc + } + charset := []string{} + for _, name := range currentCard.Characters { + if !strInSlice(name, cbc) { + charset = append(charset, name) + } + } + charset = append(charset, cbc...) + return charset +} diff --git a/models/card.go b/models/card.go index adfb030..9bf6665 100644 --- a/models/card.go +++ b/models/card.go @@ -31,18 +31,20 @@ func (c *CharCardSpec) Simplify(userName, fpath string) *CharCard { fm := strings.ReplaceAll(strings.ReplaceAll(c.FirstMes, "{{char}}", c.Name), "{{user}}", userName) sysPr := strings.ReplaceAll(strings.ReplaceAll(c.Description, "{{char}}", c.Name), "{{user}}", userName) return &CharCard{ - SysPrompt: sysPr, - FirstMsg: fm, - Role: c.Name, - FilePath: fpath, + SysPrompt: sysPr, + FirstMsg: fm, + Role: c.Name, + FilePath: fpath, + Characters: []string{c.Name, userName}, } } type CharCard struct { - SysPrompt string `json:"sys_prompt"` - FirstMsg string `json:"first_msg"` - Role string `json:"role"` - FilePath string `json:"filepath"` + SysPrompt string `json:"sys_prompt"` + FirstMsg string `json:"first_msg"` + Role string `json:"role"` + Characters []string `json:"chars"` + FilePath string `json:"filepath"` } func (cc *CharCard) ToSpec(userName string) *CharCardSpec { diff --git a/sysprompts/alice_bob_carl.json b/sysprompts/alice_bob_carl.json index abde0f2..8c7b8e2 100644 --- a/sysprompts/alice_bob_carl.json +++ b/sysprompts/alice_bob_carl.json @@ -4,5 +4,6 @@ "role2": "Bob", "role3": "Carl", "filepath": "sysprompts/alice_bob_carl.json", + "chars": ["Alice", "Bob", "Carl"], "first_msg": "Hey guys! Want to play Alias like game? I'll tell Bob a word and he needs to describe that word so Carl can guess what it was?" } diff --git a/tui.go b/tui.go index dc90db9..54a4e32 100644 --- a/tui.go +++ b/tui.go @@ -836,7 +836,7 @@ func init() { if injectRole { status = "enabled" } - if err := notifyUser("injectRole", fmt.Sprintf("Role injection %s", status)); err != nil { + if err := notifyUser("injectRole", "Role injection "+status); err != nil { logger.Error("failed to send notification", "error", err) } updateStatusLine() @@ -1218,7 +1218,8 @@ func init() { if cfg.WriteNextMsgAsCompletionAgent != "" { botPersona = cfg.WriteNextMsgAsCompletionAgent } - roles := chatBody.ListRoles() + // roles := chatBody.ListRoles() + roles := listChatRoles() if len(roles) == 0 { logger.Warn("empty roles in chat") } @@ -1229,11 +1230,9 @@ func init() { if strings.EqualFold(role, botPersona) { if i == len(roles)-1 { cfg.WriteNextMsgAsCompletionAgent = roles[0] // reached last, get first - botPersona = cfg.WriteNextMsgAsCompletionAgent break } cfg.WriteNextMsgAsCompletionAgent = roles[i+1] // get next role - botPersona = cfg.WriteNextMsgAsCompletionAgent // logger.Info("picked role", "roles", roles, "index", i+1) break } -- cgit v1.2.3