Skip to content

Commit 36e6549

Browse files
authored
feat(history): allow title modification via a format_title function (ravitemer#35)
1 parent 2263748 commit 36e6549

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ require("codecompanion").setup({
113113
refresh_every_n_prompts = 0, -- e.g., 3 to refresh after every 3rd user prompt
114114
---Maximum number of times to refresh the title (default: 3)
115115
max_refreshes = 3,
116+
format_title = function(original_title)
117+
-- this can be a custom function that applies some custom
118+
-- formatting to the title.
119+
return original_title
120+
end
116121
},
117122
---On exiting and entering neovim, loads the last chat on opening chat
118123
continue_last_chat = false,

doc/codecompanion-history.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*codecompanion-history.txt* For NVIM v0.8.0 Last change: 2025 June 24
1+
*codecompanion-history.txt* For NVIM v0.8.0 Last change: 2025 July 05
22

33
==============================================================================
44
Table of Contents *codecompanion-history-table-of-contents*
@@ -159,6 +159,11 @@ ADD HISTORY EXTENSION TO CODECOMPANION CONFIG ~
159159
refresh_every_n_prompts = 0, -- e.g., 3 to refresh after every 3rd user prompt
160160
---Maximum number of times to refresh the title (default: 3)
161161
max_refreshes = 3,
162+
format_title = function(original_title)
163+
-- this can be a custom function that applies some custom
164+
-- formatting to the title.
165+
return original_title
166+
end
162167
},
163168
---On exiting and entering neovim, loads the last chat on opening chat
164169
continue_last_chat = false,

lua/codecompanion/_extensions/history/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ local default_opts = {
5555
refresh_every_n_prompts = 0,
5656
---Maximum number of times to refresh the title (default: 3)
5757
max_refreshes = 3,
58+
format_title = nil,
5859
},
5960
---On exiting and entering neovim, loads the last chat on opening chat
6061
continue_last_chat = false,
@@ -189,6 +190,9 @@ function History:_setup_autocommands()
189190
local should_generate, is_refresh = self.title_generator:should_generate(chat)
190191
if should_generate then
191192
self.title_generator:generate(chat, function(generated_title)
193+
if type(self.opts.title_generation_opts.format_title) == "function" then
194+
generated_title = self.opts.title_generation_opts.format_title(generated_title)
195+
end
192196
if generated_title and generated_title ~= "" then
193197
-- Always update buffer title for feedback
194198
self.ui:_set_buf_title(chat.bufnr, generated_title)

lua/codecompanion/_extensions/history/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
---@field model? string? The model of the adapter to use for generation
1212
---@field refresh_every_n_prompts? number Number of user prompts after which to refresh the title (0 to disable)
1313
---@field max_refreshes? number Maximum number of times to refresh the title (default: 3)
14+
---@field format_title? fun(original_title: string):string a function that applies a custom transformation to the title.
1415

1516
---@class HistoryOpts
1617
---@field default_buf_title? string A name for the chat buffer that tells that this is an auto saving chat

0 commit comments

Comments
 (0)