feat: respect agents.md (#2376)
This commit is contained in:
@@ -5,6 +5,7 @@ local uv = vim.uv
|
||||
local curl = require("plenary.curl")
|
||||
|
||||
local Utils = require("avante.utils")
|
||||
local Prompts = require("avante.utils.prompts")
|
||||
local Config = require("avante.config")
|
||||
local Path = require("avante.path")
|
||||
local Providers = require("avante.providers")
|
||||
@@ -385,6 +386,9 @@ function M.generate_prompts(opts)
|
||||
if opts.tools then tools = vim.list_extend(tools, opts.tools) end
|
||||
if opts.prompt_opts and opts.prompt_opts.tools then tools = vim.list_extend(tools, opts.prompt_opts.tools) end
|
||||
|
||||
local agents_rules = Prompts.get_agents_rules_prompt()
|
||||
if agents_rules then system_prompt = system_prompt .. "\n\n" .. agents_rules end
|
||||
|
||||
---@type AvantePromptOptions
|
||||
return {
|
||||
system_prompt = system_prompt,
|
||||
|
||||
@@ -210,4 +210,27 @@ I've successfully created the requested React component with the following featu
|
||||
return system_prompt
|
||||
end
|
||||
|
||||
--- Get the content of AGENTS.md or CLAUDE.md or OPENCODE.md
|
||||
---@return string | nil
|
||||
function M.get_agents_rules_prompt()
|
||||
local Utils = require("avante.utils")
|
||||
local project_root = Utils.get_project_root()
|
||||
local file_names = {
|
||||
"AGENTS.md",
|
||||
"CLAUDE.md",
|
||||
"OPENCODE.md",
|
||||
".cursorrules",
|
||||
".windsurfrules",
|
||||
Utils.join_paths(".github", "copilot-instructions.md"),
|
||||
}
|
||||
for _, file_name in ipairs(file_names) do
|
||||
local file_path = Utils.join_paths(project_root, file_name)
|
||||
if vim.fn.filereadable(file_path) == 1 then
|
||||
local content = vim.fn.readfile(file_path)
|
||||
if content then return table.concat(content, "\n") end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user