Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable history directory #18

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Default setup configuration:
prev = "[x",
},
},
history_dir = nil -- default to $project_root/.avante_chat_history
}
```

Expand Down Expand Up @@ -134,6 +135,26 @@ The following key bindings are available for use with `avante.nvim`:
- <kbd>]</kbd><kbd>x</kbd> — move to previous conflict
- <kbd>[</kbd><kbd>x</kbd> — move to next conflict

## Set up A Custom History Directory

By default, `avante.nvim` stores chat history in the project root directory under the `.avante_chat_history` folder. To change the default directory, set the `history_dir` option in the configuration.

```lua
{
history_dir = "/path/to/your/history/directory"
}
```

the `history_dir` can also be set to a function that accept project root directory and return the history directory.

```lua
{
history_dir = function(project_root)
return project_root .. "/.avante_chat_history"
end
}
```

## Roadmap

- **Enhanced AI Interactions**: Improve the depth of AI analysis and recommendations for more complex coding scenarios.
Expand Down
2 changes: 1 addition & 1 deletion lua/avante/ai_bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end

local function call_openai_api_stream(question, code_lang, code_content, on_chunk, on_complete)
local api_key = os.getenv("OPENAI_API_KEY")
if not api_key then
if not api_key and config.get().provider == "openai" then
error("OPENAI_API_KEY environment variable is not set")
end

Expand Down
1 change: 1 addition & 0 deletions lua/avante/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local config = {
prev = "[x",
},
},
history_dir = nil, -- default to $project_root/.avante_chat_history
}

function M.update(opts)
Expand Down
10 changes: 9 additions & 1 deletion lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local config = require("avante.config")
local ai_bot = require("avante.ai_bot")
local api = vim.api
local fn = vim.fn
local utils = require("avante.utils")

local RESULT_BUF_NAME = "AVANTE_RESULT"
local CONFLICT_BUF_NAME = "AVANTE_CONFLICT"
Expand Down Expand Up @@ -227,9 +228,16 @@ end

-- Function to get the chat history file path
local function get_chat_history_file()
local history_dir = config.get().history_dir
local project_root = get_project_root()
if history_dir == nil then
history_dir = Path:new(project_root, ".avante_chat_history")
elseif type(history_dir) == "function" then
history_dir = history_dir(project_root)
else
history_dir = Path:new(history_dir, fn.fnamemodify(project_root, ":~:."), ".avante_chat_history")
end
local filename = get_chat_history_filename()
local history_dir = Path:new(project_root, ".avante_chat_history")
return history_dir:joinpath(filename .. ".json")
end

Expand Down