Skip to content

Commit 5411c45

Browse files
authored
feat(gitcommit): add commit history context for message generation (#9)
* feat(gitcommit): add commit history context for message generation - introduce `use_commit_history` and `commit_history_count` options to include recent commit messages as context - update generator to pass commit history to LLM prompt for improved style consistency - implement `Git.get_commit_history` to retrieve recent commit messages from git log - update configuration, types, and example config to support and document the new feature - ensure commit history context is used across buffer, init, and generator modules * refactor(gitcommit): improve formatting and consistency - update indentation and spacing across gitcommit extension files - fix minor comment alignment and trailing comma issues in config example - standardize function parameter documentation and formatting * fix(types): correct type declarations for Git and Generator classes - move generate_commit_message function from Git class to proper Generator class - add missing get_commit_history function declaration to Git class - fix indentation and formatting issues in type annotations * style(types): remove unnecessary blank line in types.lua - delete extraneous blank line for improved code readability * docs(guide): migrate documentation to codecompanion.txt - consolidate EXTENSION_DEVELOPMENT_GUIDE.md, GEMINI.md, tools.md, and prompt_construction_en.md into codecompanion.txt - update and expand help documentation for plugin features, configuration, extension development, and tool creation - remove outdated and redundant markdown guides in favor of unified vim help file * style(gitcommit): improve code comments and docstrings - update comments and docstrings for clarity and consistency across buffer, generator, git, init, and ui modules - rephrase and simplify inline comments to enhance readability - standardize parameter descriptions and function documentation for better maintainability * docs(gitcommit): document commit history context and API - add commit history context feature to README and configuration docs - introduce programmatic API section with usage examples in README and help file - update documentation structure and configuration options for clarity * feat(workspace): add structured workspace manifest file - introduce codecompanion-workspace.json with schema and group definitions - organize extension components into logical groups for core, git, AI, UI, tools, and docs - provide metadata and file descriptions to support project tooling and documentation * docs(guide): document new get_changed_files tool and update tool options - add documentation for the get_changed_files tool, including usage and options - update tool group listings and examples to include get_changed_files - clarify and expand options for file_search, grep_search, insert_edit_into_file, and next_edit_suggestion tools - update event list with CodeCompanionChatDone event - fix and improve tool group documentation for clarity and completeness * fix(gitcommit): handle cancelled language selection gracefully - add checks for nil language selection in commit message generation - prevent further processing if user cancels language selection dialog * style(gitcommit): remove trailing whitespace in buffer.lua - clean up unnecessary whitespace for improved code consistency * docs(gitcommit): add setup function annotation and clean config usage - document Git.setup with LuaDoc annotation for configuration options - simplify git_config retrieval in generate_commit_message by removing redundant check
1 parent 4d0682e commit 5411c45

16 files changed

+5849
-1964
lines changed

EXTENSION_DEVELOPMENT_GUIDE.md

Lines changed: 0 additions & 945 deletions
This file was deleted.

GEMINI.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ A Neovim plugin extension for CodeCompanion that generates AI-powered Git commit
1010
- 🌍 **Multi-language Support** - Generate commit messages in multiple languages
1111
- 📝 **Smart Buffer Integration** - Auto-generate commit messages in gitcommit buffers with configurable keymaps
1212
- 📋 **File Filtering** - Support glob patterns to exclude files from diff analysis
13+
- 📚 **Commit History Context** - Use recent commit history to maintain consistent styling and patterns
14+
- 🔌 **Programmatic API** - Full API for external integrations and custom workflows
1315
-**Async Operations** - Non-blocking Git operations with proper error handling
1416

1517
## 📦 Installation
@@ -53,6 +55,10 @@ require("codecompanion").setup({
5355
git_tool_auto_submit_errors = false, -- Auto-submit errors to LLM
5456
git_tool_auto_submit_success = true, -- Auto-submit success to LLM
5557
gitcommit_select_count = 100, -- Number of commits shown in /gitcommit
58+
59+
-- Commit history context (optional)
60+
use_commit_history = true, -- Enable commit history context
61+
commit_history_count = 10, -- Number of recent commits for context
5662
}
5763
}
5864
}
@@ -170,6 +176,8 @@ opts = {
170176
gitcommit_select_count = 100, -- Commits shown in /gitcommit
171177
git_tool_auto_submit_errors = false, -- Auto-submit errors to LLM
172178
git_tool_auto_submit_success = true, -- Auto-submit success to LLM
179+
use_commit_history = true, -- Enable commit history context
180+
commit_history_count = 10, -- Number of recent commits for context
173181
buffer = {
174182
enabled = true, -- Enable buffer integration
175183
keymap = "<leader>gc", -- Keymap
@@ -182,6 +190,38 @@ opts = {
182190

183191
</details>
184192

193+
## 🔌 Programmatic API
194+
195+
The extension provides a comprehensive API for external integrations:
196+
197+
```lua
198+
local gitcommit = require("codecompanion._extensions.gitcommit")
199+
200+
-- Generate commit message programmatically
201+
gitcommit.exports.generate("English", function(result, error)
202+
if result then
203+
print("Generated:", result)
204+
else
205+
print("Error:", error)
206+
end
207+
end)
208+
209+
-- Check if in git repository
210+
if gitcommit.exports.is_git_repo() then
211+
print("In git repository")
212+
end
213+
214+
-- Get git status
215+
local status = gitcommit.exports.git_tool.status()
216+
print("Git status:", status)
217+
218+
-- Stage files
219+
gitcommit.exports.git_tool.stage({"file1.txt", "file2.txt"})
220+
221+
-- Create and checkout branch
222+
gitcommit.exports.git_tool.create_branch("feature/new-feature", true)
223+
```
224+
185225
## 📚 Documentation
186226

187227
For detailed documentation, see: `:help codecompanion-gitcommit`

codecompanion-workspace.json

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"name": "CodeCompanion GitCommit Extension",
4+
"version": "1.0.0",
5+
"system_prompt": "You are helping with a Neovim plugin that extends CodeCompanion to provide AI-powered Git commit message generation following Conventional Commits specification. The plugin integrates deeply with Git workflows and provides comprehensive tooling for repository management through LLM-powered chat interfaces.",
6+
"vars": {
7+
"project_name": "codecompanion-gitcommit.nvim",
8+
"main_module": "codecompanion._extensions.gitcommit"
9+
},
10+
"groups": [
11+
{
12+
"name": "core_extension",
13+
"system_prompt": "This group contains the core extension entry point and configuration. Focus on the main initialization logic, extension setup, command registration, and overall architecture of how the plugin integrates with CodeCompanion.",
14+
"data": [
15+
"main_init",
16+
"extension_config",
17+
"type_definitions"
18+
]
19+
},
20+
{
21+
"name": "git_operations",
22+
"system_prompt": "This group handles all Git repository operations including diff analysis, commit execution, repository validation, and file filtering. Focus on Git command execution, repository state management, and the core Git integration logic.",
23+
"data": [
24+
"git_core",
25+
"git_buffer_integration"
26+
]
27+
},
28+
{
29+
"name": "ai_generation",
30+
"system_prompt": "This group manages the AI-powered commit message generation using LLM adapters. Focus on prompt engineering, LLM communication, response handling, and the generation workflow for creating Conventional Commits compliant messages.",
31+
"data": [
32+
"message_generator",
33+
"language_selection"
34+
]
35+
},
36+
{
37+
"name": "user_interface",
38+
"system_prompt": "This group handles user interaction components including buffer integration for gitcommit buffers, floating window displays, and user interface elements. Focus on user experience, interactive elements, and visual presentation.",
39+
"data": [
40+
"buffer_management",
41+
"ui_components"
42+
]
43+
},
44+
{
45+
"name": "git_tools",
46+
"system_prompt": "This group provides comprehensive Git tooling for CodeCompanion chat integration, including read-only operations, write operations, and the Git bot assistant. Focus on tool schemas, command execution, safety mechanisms, and chat integration.",
47+
"data": [
48+
"git_tools_core",
49+
"git_read_tool",
50+
"git_edit_tool"
51+
]
52+
},
53+
{
54+
"name": "documentation_and_examples",
55+
"system_prompt": "This group contains project documentation, usage examples, and configuration templates. Focus on user guidance, feature documentation, and setup instructions.",
56+
"data": [
57+
"readme_docs",
58+
"config_examples",
59+
"help_documentation"
60+
]
61+
}
62+
],
63+
"data": {
64+
"main_init": {
65+
"type": "file",
66+
"path": "lua/codecompanion/_extensions/gitcommit/init.lua",
67+
"description": "Main extension entry point with setup function, command registration, tool integration, and programmatic API exports"
68+
},
69+
"extension_config": {
70+
"type": "file",
71+
"path": "lua/codecompanion/_extensions/gitcommit/config.lua",
72+
"description": "Extension configuration management with default options and validation"
73+
},
74+
"type_definitions": {
75+
"type": "file",
76+
"path": "lua/codecompanion/_extensions/gitcommit/types.lua",
77+
"description": "TypeScript-style type annotations and interface definitions for the extension"
78+
},
79+
"git_core": {
80+
"type": "file",
81+
"path": "lua/codecompanion/_extensions/gitcommit/git.lua",
82+
"description": "Core Git operations including repository validation, diff analysis, commit execution, and file filtering logic"
83+
},
84+
"git_buffer_integration": {
85+
"type": "file",
86+
"path": "lua/codecompanion/_extensions/gitcommit/buffer.lua",
87+
"description": "Git commit buffer integration with automatic message generation and keymap setup"
88+
},
89+
"message_generator": {
90+
"type": "file",
91+
"path": "lua/codecompanion/_extensions/gitcommit/generator.lua",
92+
"description": "AI-powered commit message generation using CodeCompanion's LLM adapters with prompt engineering and response handling"
93+
},
94+
"language_selection": {
95+
"type": "file",
96+
"path": "lua/codecompanion/_extensions/gitcommit/langs.lua",
97+
"description": "Multi-language support for commit message generation with language selection UI"
98+
},
99+
"buffer_management": {
100+
"type": "file",
101+
"path": "lua/codecompanion/_extensions/gitcommit/buffer.lua",
102+
"description": "Git commit buffer integration and automatic commit message insertion"
103+
},
104+
"ui_components": {
105+
"type": "file",
106+
"path": "lua/codecompanion/_extensions/gitcommit/ui.lua",
107+
"description": "Floating window UI for displaying commit messages with interactive options (copy, commit, edit)"
108+
},
109+
"git_tools_core": {
110+
"type": "file",
111+
"path": "lua/codecompanion/_extensions/gitcommit/tools/git.lua",
112+
"description": "Core Git tool utilities and shared functionality for read/write operations"
113+
},
114+
"git_read_tool": {
115+
"type": "file",
116+
"path": "lua/codecompanion/_extensions/gitcommit/tools/git_read.lua",
117+
"description": "Read-only Git operations tool for CodeCompanion chat (status, log, diff, blame, etc.)"
118+
},
119+
"git_edit_tool": {
120+
"type": "file",
121+
"path": "lua/codecompanion/_extensions/gitcommit/tools/git_edit.lua",
122+
"description": "Write-access Git operations tool for CodeCompanion chat (stage, commit, branch management, etc.)"
123+
},
124+
"readme_docs": {
125+
"type": "file",
126+
"path": "README.md",
127+
"description": "Main project documentation with features, installation, usage, and API reference"
128+
},
129+
"config_examples": {
130+
"type": "file",
131+
"path": "config_example.lua",
132+
"description": "Basic configuration example for the extension setup"
133+
},
134+
"help_documentation": {
135+
"type": "file",
136+
"path": "doc/codecompanion-gitcommit.txt",
137+
"description": "Vim help documentation for the extension"
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)