Skip to content

Commit 9352fd2

Browse files
ravitemerDavidyz
andauthored
feat: summary generation and retrieval with @memory tool (#23)
* wip: summary * refactor: updating title * refactor: show better picker items * feat: add previewing summary with gps * refactor: move file utils into utils.lua * refactor: types * docs: update README with summary feature * tests: fix failing test * fix: type names * feat: allow refreshing title as the conversation grows (fixes #25) * chore: make all * feat(memory): use vectorcode to index summaries and retreive with memory tool (#28) * feat(memories): proof-of-concept vectorcode integration * feat(memory): integrate vectorcode memory tool * docs(memory): document VectorCode memory tool and improve parameter description * fix(memory): fix vectorcode integration and handle missing vectorcode installation * refactor(memory): remove the use of vectorcode nvim plugin and directly interact with the CLI * fix: streaming in chat not working once title or summary generated * refactor: add error handler and config option * refactor(memory): use autocmd to trigger `vectorise` * fix(memory): make sure memory module isn't loaded when vectorcode is not installed * feat(memory): add notifications for vectorising progress * refactor(memory): use memory opts * feat(memory): add `index_on_startup` option --------- Co-authored-by: ravitemer <[email protected]> * docs: update memory documentation * fix: merge conflicts * fix: duplicate context block when restoring chats with default_tools (rel to #1610) * refactor: add proper namespaced types * fix(memory): handle empty keywords * feat: resolve merge conflicts from main * tests: add tests for summary feature * refactor: remove `gps` and add summaries as refs to chat, allow deleting summaries * fix: typo * fix: minor fixes * feat: add `format_summary` option * chore: make all * tests: add format_summary test * docs: add removed comments * docs: add warning #34 --------- Co-authored-by: David <[email protected]>
1 parent 36e6549 commit 9352fd2

19 files changed

+3425
-605
lines changed

README.md

Lines changed: 140 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A history management extension for [codecompanion.nvim](https://codecompanion.ol
1515

1616
## ✨ Features
1717

18+
### 🤖 Chat Management
1819
- 💾 Flexible chat saving:
1920
- Automatic session saving (can be disabled)
2021
- Manual save with dedicated keymap
@@ -27,6 +28,18 @@ A history management extension for [codecompanion.nvim](https://codecompanion.ol
2728
- 🏢 **Project-aware filtering**: Filter chats by workspace/project context
2829
- 📋 **Chat duplication**: Easily duplicate chats to create variations or backups
2930

31+
### 📝 Summary System
32+
- **Manual summary generation**: Create summaries for any chat with `gcs`
33+
- **Intelligent content processing**: Extracts meaningful conversation content while filtering noise
34+
- **Chunked summarization**: Handles large conversations by splitting into manageable chunks
35+
- **Customizable generation**: Configure adapter, model, and system prompts
36+
- **Summary browsing**: Dedicated browser with `gbs` to explore all summaries
37+
38+
### 🧠 Memory System (@memory tool)
39+
- **Vector-based search**: Uses VectorCode CLI to index and search through chat summaries
40+
- **Automatic indexing**: Optionally index summaries as they are generated
41+
- **Smart integration**: Available as `@memory` tool in new chats when VectorCode is installed
42+
3043
The following CodeCompanion features are preserved when saving and restoring chats:
3144

3245
| Feature | Status | Notes |
@@ -58,6 +71,7 @@ When restoring a chat:
5871

5972
- Neovim >= 0.8.0
6073
- [codecompanion.nvim](https://codecompanion.olimorris.dev/)
74+
- [VectorCode CLI](https://github.com/Davidyz/VectorCode) (optional, for `@memory` tool)
6175
- [snacks.nvim](https://github.com/folke/snacks.nvim) (optional, for enhanced picker)
6276
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) (optional, for enhanced picker)
6377
- [fzf-lua](https://github.com/ibhagwan/fzf-lua) (optional, for enhanced picker)
@@ -96,6 +110,8 @@ require("codecompanion").setup({
96110
expiration_days = 0,
97111
-- Picker interface (auto resolved to a valid picker)
98112
picker = "telescope", --- ("telescope", "snacks", "fzf-lua", or "default")
113+
---Optional filter function to control which chats are shown when browsing
114+
chat_filter = nil, -- function(chat_data) return boolean end
99115
-- Customize picker keymaps (optional)
100116
picker_keymaps = {
101117
rename = { n = "r", i = "<M-r>" },
@@ -127,31 +143,77 @@ require("codecompanion").setup({
127143
dir_to_save = vim.fn.stdpath("data") .. "/codecompanion-history",
128144
---Enable detailed logging for history extension
129145
enable_logging = false,
130-
---Optional filter function to control which chats are shown when browsing
131-
chat_filter = nil, -- function(chat_data) return boolean end
146+
147+
-- Summary system
148+
summary = {
149+
-- Keymap to generate summary for current chat (default: "gcs")
150+
create_summary_keymap = "gcs",
151+
-- Keymap to browse summaries (default: "gbs")
152+
browse_summaries_keymap = "gbs",
153+
154+
generation_opts = {
155+
adapter = nil, -- defaults to current chat adapter
156+
model = nil, -- defaults to current chat model
157+
context_size = 90000, -- max tokens that the model supports
158+
include_references = true, -- include slash command content
159+
include_tool_outputs = true, -- include tool execution results
160+
system_prompt = nil, -- custom system prompt (string or function)
161+
format_summary = nil, -- custom function to format generated summary e.g to remove <think/> tags from summary
162+
},
163+
},
164+
165+
-- Memory system (requires VectorCode CLI)
166+
memory = {
167+
-- Automatically index summaries when they are generated
168+
auto_create_memories_on_summary_generation = true,
169+
-- Path to the VectorCode executable
170+
vectorcode_exe = "vectorcode",
171+
-- Tool configuration
172+
tool_opts = {
173+
-- Default number of memories to retrieve
174+
default_num = 10
175+
},
176+
-- Enable notifications for indexing progress
177+
notify = true,
178+
-- Index all existing memories on startup
179+
-- (requires VectorCode 0.6.12+ for efficient incremental indexing)
180+
index_on_startup = false,
181+
},
132182
}
133183
}
134184
}
135185
})
136186
```
137187

188+
189+
> [!WARNING]
190+
> Title and summary generation defaults to current chat's adapter and model. Make sure to set cheaper models in `title_generation_opts` and `summary.generation_opts` to avoid using premium models.
191+
192+
138193
## 🛠️ Usage
139194

140195
#### 🎯 Commands
141196

142197
- `:CodeCompanionHistory` - Open the history browser
198+
- `:CodeCompanionSummaries` - Browse all summaries
143199

144200

145201
#### ⌨️ Chat Buffer Keymaps
146202

203+
**History Management:**
147204
- `gh` - Open history browser (customizable via `opts.keymap`)
148205
- `sc` - Save current chat manually (customizable via `opts.save_chat_keymap`)
149206

207+
**Summary System:**
208+
- `gcs` - Generate summary for current chat (customizable via `opts.summary.create_summary_keymap`)
209+
- `gbs` - Browse saved summaries (customizable via `opts.summary.browse_summaries_keymap`)
210+
150211
#### 📚 History Browser
151212

152213
The history browser shows all your saved chats with:
153214
- Title (auto-generated or custom)
154-
- Last updated time
215+
- Summary indicator (📝 icon for chats with summaries)
216+
- Token estimates and relative timestamps
155217
- Preview of chat contents
156218

157219
Actions in history browser:
@@ -165,7 +227,46 @@ Actions in history browser:
165227
- `<M-r>` (Alt+r) - Rename selected chat
166228
- `<C-y>` - Duplicate selected chat
167229

168-
> Note: Delete, rename, and duplicate actions are only available in telescope, snacks, and fzf-lua pickers. Multiple chats can be selected for deletion using picker's multi-select feature (press `<Tab>`). Duplication is limited to one chat at a time.
230+
#### 📝 Summary Browser
231+
232+
The summary browser shows all your generated summaries with:
233+
- Chat title (from original conversation)
234+
- Project context and relative timestamps
235+
- Preview of summary content
236+
237+
Actions in summary browser:
238+
- `<CR>` - Add the summary to the current chat
239+
- Normal mode:
240+
- `d` - Delete selected summary(s)
241+
- Insert mode:
242+
- `<M-d>` (Alt+d) - Delete selected summary(s)
243+
244+
245+
## The `@memory` tool
246+
247+
If you have installed the [VectorCode](https://github.com/Davidyz/VectorCode) CLI,
248+
this plugin will use VectorCode to create an index for your chat summaries and create
249+
a tool called `@memory`. This tool gives the LLM the ability to search for
250+
(the summary of) previous chats so that you can refer to them in a new chat.
251+
252+
Available options for the memory submodule:
253+
```lua
254+
opts.memory = {
255+
auto_create_memories_on_summary_generation = true,
256+
-- path to the `vectorcode` executable
257+
vectorcode_exe = "vectorcode",
258+
tool_opts = {
259+
-- default number of memories to retrieve
260+
default_num = 10
261+
},
262+
-- whether to enable notification
263+
notify = true,
264+
-- whether to automatically update the index of all existing memories on startup
265+
-- (requires VectorCode 0.6.12+ for efficient incremental indexing)
266+
index_on_startup = false,
267+
}
268+
```
269+
169270

170271
#### 🔄 Title Refresh Feature
171272

@@ -224,8 +325,8 @@ Each chat index entry (used in filtering) includes the following information:
224325
The history extension exports the following functions that can be accessed via `require("codecompanion").extensions.history`:
225326

226327
```lua
227-
-- Get the storage location for saved chats
228-
get_location(): string?
328+
-- Chat Management
329+
get_location(): string? -- Get storage location
229330

230331
-- Save a chat to storage (uses last chat if none provided)
231332
save_chat(chat?: CodeCompanion.Chat)
@@ -244,6 +345,20 @@ delete_chat(save_id: string): boolean
244345

245346
-- Duplicate a chat by its save_id
246347
duplicate_chat(save_id: string, new_title?: string): string?
348+
349+
350+
-- Summary Management
351+
--- Generate a summary for the current chat
352+
generate_summary(chat?: CodeCompanion.Chat)
353+
354+
--- Delete a sumamry
355+
delete_summary(summary_id: string)
356+
357+
--- Get summaries index
358+
get_summaries(): table<string, SummaryIndexData>
359+
360+
--- Load summary
361+
load_summary(summary_id: string): string?
247362
```
248363

249364
Example usage:
@@ -257,20 +372,26 @@ end)
257372

258373
-- Get all saved chats metadata
259374
local chats = history.get_chats()
260-
261-
-- Load a specific chat
262375
local chat_data = history.load_chat("some_save_id")
263-
264-
-- Delete a chat
265376
history.delete_chat("some_save_id")
266377

267378
-- Duplicate a chat with custom title
268379
local new_save_id = history.duplicate_chat("some_save_id", "My Custom Copy")
269380

270381
-- Duplicate a chat with auto-generated title (appends "(1)")
271382
local new_save_id = history.duplicate_chat("some_save_id")
383+
384+
-- Summary operations
385+
history.generate_summary() -- generates for current chat
386+
387+
local summaries = history.get_summaries()
388+
389+
local summary_content = history.load_summary("some_save_id")
390+
391+
272392
```
273393

394+
274395
## ⚙️ How It Works
275396

276397

@@ -389,9 +510,13 @@ The extension integrates with CodeCompanion through a robust event-driven archit
389510

390511
</details>
391512

392-
## 📝 TODOs
513+
## 🔮 Future Roadmap
393514

394-
- [x] Add support for additional pickers like snacks, fzf etc
515+
516+
### Upcoming Features
517+
- [ ] Auto-summary generation options
518+
- [ ] Summary search and filtering
519+
- [ ] Integration with vector databases
395520

396521
## 🔌 Related Extensions
397522

@@ -400,9 +525,10 @@ The extension integrates with CodeCompanion through a robust event-driven archit
400525

401526
## 🙏 Acknowledgements
402527

403-
Special thanks to [Oli Morris](https://github.com/olimorris) for creating the amazing [CodeCompanion.nvim](https://codecompanion.olimorris.dev) plugin - a highly configurable and powerful coding assistant for Neovim.
528+
Special thanks to:
529+
- [Oli Morris](https://github.com/olimorris) for creating the amazing [CodeCompanion.nvim](https://codecompanion.olimorris.dev) plugin - a highly configurable and powerful coding assistant for Neovim.
530+
- [David](https://github.com/Davidyz) for the awesome [VectorCode](https://github.com/Davidyz/VectorCode) CLI and adding the @memory tool integration.
404531

405532
## 📄 License
406533

407534
MIT
408-

0 commit comments

Comments
 (0)