Skip to content
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require("pi").setup({
provider = "openrouter",
model = "openrouter/free",
thinking = "off", -- be careful, thinking is time-consuming, it's not a great experience if you want simplicity
tools = { "bash" },
system_prompt = "You are a helpful assistant.",
append_system_prompt = "Always respond concisely.",
context = {
Expand All @@ -84,6 +85,7 @@ require("pi").setup({
| `provider` | `nil` | pi provider to use. If omitted, pi uses its own default configuration. |
| `model` | `nil` | Model name to use. If omitted, pi uses its own default configuration. |
| `thinking` | `"off"` | Sets pi's thinking level (`--thinking`). Supported values: `off`, `minimal`, `low`, `medium`, `high`, `xhigh`. |
| `tools` | `nil` | Array of tool names to enable (`read,`edit` and `write` are always enabled). If omitted, pi uses its own default configuration. |
| `system_prompt` | `nil` | Passes a custom system prompt to pi (`--system-prompt`). Use with care, since this overrides pi's generated baseline instructions. |
| `append_system_prompt` | `nil` | Appends text to the system prompt (`--append-system-prompt`). pi.nvim always appends its non-interactive execution instruction, and this option is concatenated after it. |
| `context.max_bytes` | `24000` | Maximum size in bytes for sent context before trimming. |
Expand Down
11 changes: 11 additions & 0 deletions lua/pi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ M.defaults = {
provider = nil,
model = nil,
thinking = "off",
tools = nil,
system_prompt = nil,
append_system_prompt = nil,
context = {
Expand Down Expand Up @@ -106,6 +107,16 @@ function M.validate(opts)
error("pi.nvim: thinking must be one of: off, minimal, low, medium, high, xhigh")
end
end
if opts.tools ~= nil then
if type(opts.tools) ~= "table" then
error("pi.nvim: tools must be a table")
end
for _, value in ipairs(opts.tools) do
if type(value) ~= "string" then
error("pi.nvim: tools must be a table of strings")
end
end
end
if opts.system_prompt ~= nil and type(opts.system_prompt) ~= "string" then
error("pi.nvim: system_prompt must be a string")
end
Expand Down
10 changes: 10 additions & 0 deletions lua/pi/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ function M.get_cmd()
table.insert(cmd, "--thinking")
table.insert(cmd, cfg.thinking)
end
if cfg.tools then
local tools = { "read", "edit", "write" }
for _, tool in ipairs(cfg.tools) do
if not vim.tbl_contains(tools, tool) then
table.insert(tools, tool)
end
end
table.insert(cmd, "--tools")
table.insert(cmd, table.concat(tools, ","))
end
if cfg.system_prompt then
table.insert(cmd, "--system-prompt")
table.insert(cmd, cfg.system_prompt)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_pi_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,32 @@ local function test_append_system_prompt_is_concatenated()
MiniTest.expect.no_equality(cmd[append_idx + 1]:match("Always run tests"), nil)
end

local function test_tools_configs()
local configs = {
{ setup = 'require("pi").setup({ tools = {} })', expected = "read,edit,write" },
{ setup = 'require("pi").setup({ tools = nil })', expected = nil },
{ setup = 'require("pi").setup({ tools = { "edit" } })', expected = "read,edit,write" },
{ setup = 'require("pi").setup({ tools = { "bash" } })', expected = "read,edit,write,bash" },
{ setup = 'require("pi").setup({ tools = { "custom" } })', expected = "read,edit,write,custom" },
}

for _, config in ipairs(configs) do
setup_test_env(config.setup)
setup_buffer({ "code" }, "/test/file.lua")

local system = run_pi_ask("test")
local cmd = system.get_cmd()
local tools_idx = has_arg(cmd, "--tools")

if config.expected then
MiniTest.expect.no_equality(tools_idx, nil)
MiniTest.expect.equality(cmd[tools_idx + 1], config.expected)
else
MiniTest.expect.equality(tools_idx, nil)
end
end
end

local function test_second_request_is_blocked_while_running()
setup_test_env()
setup_buffer({ "code" }, "/test/file.lua")
Expand Down Expand Up @@ -933,6 +959,7 @@ T["PiAsk"]["default thinking is off"] = test_default_thinking_is_off
T["PiAsk"]["thinking option adds cli flag"] = test_thinking_option_adds_cli_flag
T["PiAsk"]["invalid thinking option errors"] = test_invalid_thinking_option_errors
T["PiAsk"]["append_system_prompt is concatenated with plugin prompt"] = test_append_system_prompt_is_concatenated
T["PiAsk"]["configures tools"] = test_tools_configs

T["PiAskSelection"] = MiniTest.new_set()
T["PiAskSelection"]["uses nearby context"] = test_selection_uses_nearby_context
Expand Down
Loading