diff --git a/pkg/lmcli/config.go b/pkg/lmcli/config.go index f1949b1..e684f3f 100644 --- a/pkg/lmcli/config.go +++ b/pkg/lmcli/config.go @@ -15,8 +15,7 @@ type Config struct { Temperature *float32 `yaml:"temperature" default:"0.2"` SystemPrompt string `yaml:"systemPrompt,omitempty"` SystemPromptFile string `yaml:"systemPromptFile,omitempty"` - // CLI only - Agent string `yaml:"-"` + Agent string `yaml:"agent"` } `yaml:"defaults"` Conversations *struct { TitleGenerationModel *string `yaml:"titleGenerationModel" default:"gpt-3.5-turbo"` diff --git a/pkg/tui/model/model.go b/pkg/tui/model/model.go index 88c54cf..60645e7 100644 --- a/pkg/tui/model/model.go +++ b/pkg/tui/model/model.go @@ -37,6 +37,25 @@ func (m *AppModel) ClearConversation() { m.RootMessages = []api.Message{} } +func (m *AppModel) ApplySystemPrompt() { + var system string + agent := m.Ctx.GetAgent(m.Ctx.Config.Defaults.Agent) + if agent != nil && agent.SystemPrompt != "" { + system = agent.SystemPrompt + } + if system == "" { + system = m.Ctx.DefaultSystemPrompt() + } + if system != "" { + m.Messages = api.ApplySystemPrompt(m.Messages, system, false) + } +} + +func (m *AppModel) NewConversation() { + m.ClearConversation() + m.ApplySystemPrompt() +} + func (m *AppModel) LoadConversations() (error, []LoadedConversation) { messages, err := m.Ctx.Store.LatestConversationMessages() if err != nil { diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index 16c4c6c..df1fec3 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -38,6 +38,7 @@ func initialModel(ctx *lmcli.Context, opts LaunchOptions) *Model { Ctx: ctx, Conversation: opts.InitialConversation, } + app.NewConversation() m := Model{ App: app, diff --git a/pkg/tui/views/chat/chat.go b/pkg/tui/views/chat/chat.go index 980289d..8a98f43 100644 --- a/pkg/tui/views/chat/chat.go +++ b/pkg/tui/views/chat/chat.go @@ -139,17 +139,6 @@ func Chat(app *model.AppModel) *Model { m.replyCursor.SetChar(" ") m.replyCursor.Focus() - system := app.Ctx.DefaultSystemPrompt() - - agent := app.Ctx.GetAgent(app.Ctx.Config.Defaults.Agent) - if agent != nil && agent.SystemPrompt != "" { - system = agent.SystemPrompt - } - - if system != "" { - m.App.Messages = api.ApplySystemPrompt(m.App.Messages, system, false) - } - m.input.Focus() m.input.MaxHeight = 0 m.input.CharLimit = 0 diff --git a/pkg/tui/views/chat/input.go b/pkg/tui/views/chat/input.go index 5d04008..f2f56ad 100644 --- a/pkg/tui/views/chat/input.go +++ b/pkg/tui/views/chat/input.go @@ -53,7 +53,7 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { m.updateContent() return shared.KeyHandled(msg) case "ctrl+n": - m.App.ClearConversation() + m.App.NewConversation() m.rebuildMessageCache() m.updateContent() return shared.KeyHandled(msg) diff --git a/pkg/tui/views/conversations/conversations.go b/pkg/tui/views/conversations/conversations.go index 78c5836..60af450 100644 --- a/pkg/tui/views/conversations/conversations.go +++ b/pkg/tui/views/conversations/conversations.go @@ -97,7 +97,7 @@ func (m *Model) handleInput(msg tea.KeyMsg) tea.Cmd { } return shared.KeyHandled(msg) case "n": - m.App.ClearConversation() + m.App.NewConversation() return shared.ChangeView(shared.ViewChat) case "d": if !m.confirmPrompt.Focused() && len(m.App.Conversations) > 0 && m.cursor < len(m.App.Conversations) {