Skip to content

Commit e00e45d

Browse files
committed
wip
1 parent 9b80578 commit e00e45d

File tree

13 files changed

+80
-138
lines changed

13 files changed

+80
-138
lines changed

doc/codecompanion.txt

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*codecompanion.txt* For NVIM v0.11 Last change: 2025 December 19
1+
*codecompanion.txt* For NVIM v0.11 Last change: 2025 December 21
22

33
==============================================================================
44
Table of Contents *codecompanion-table-of-contents*
@@ -997,10 +997,9 @@ The configuration for both types of adapters is exactly the same, however they
997997
sit within their own tables (`adapters.http.*` and `adapters.acp.*`) and have
998998
different options available. HTTP adapters use `models` to allow users to
999999
select the specific LLM they’d like to interact with. ACP adapters use
1000-
`commands` to allow users to customize their interaction with agents
1001-
(e.g. enabling `yolo` mode). As there is a lot of shared functionality between
1002-
the two adapters, it is recommend that you read this page alongside the ACP
1003-
one.
1000+
`commands` to allow users to customize their interaction with agents (e.g.�
1001+
enabling `yolo` mode). As there is a lot of shared functionality between the
1002+
two adapters, it is recommend that you read this page alongside the ACP one.
10041003

10051004

10061005
CHANGING AN ADAPTER ~
@@ -1054,7 +1053,7 @@ the adapter’s URL, headers, parameters and other fields at runtime.
10541053
<https://github.com/olimorris/codecompanion.nvim/discussions/601>
10551054
Supported `env` value types: - **Plain environment variable name (string)**: if
10561055
the value is the name of an environment variable that has already been set
1057-
(e.g. `"HOME"` or `"GEMINI_API_KEY"`), the plugin will read the value. -
1056+
(e.g.`"HOME"` or `"GEMINI_API_KEY"`), the plugin will read the value. -
10581057
**Command (string prefixed with cmd:)**: any value that starts with `cmd:` will
10591058
be executed via the shell. Example: `"cmd:op read
10601059
op://personal/Gemini/credential --no-newline"`. - **Function**: you can provide
@@ -2751,7 +2750,7 @@ The fastest way to copy an LLM’s code output is with `gy`. This will yank the
27512750
nearest codeblock.
27522751

27532752

2754-
APPLYING AN LLMS EDITS TO A BUFFER OR FILE ~
2753+
APPLYING AN LLM€�S EDITS TO A BUFFER OR FILE ~
27552754

27562755
The |codecompanion-usage-chat-buffer-tools-files| tool, combined with the
27572756
|codecompanion-usage-chat-buffer-variables.html-buffer| variable or
@@ -2856,19 +2855,8 @@ CodeCompanion provides comprehensive support for the ACP specification:
28562855

28572856
SUPPORTED ADAPTERS
28582857

2859-
-----------------------------------------------------------------------
2860-
Adapter Description Special Features
2861-
--------------- ----------------------- -------------------------------
2862-
Claude Code Anthropic’s Claude Code OAuth authentication, tool
2863-
CLI output trimming
2858+
Please see the |codecompanion-configuration-adapters-acp| page.
28642859

2865-
Gemini CLI Google’s Gemini CLI Multiple auth methods (OAuth,
2866-
API key, Vertex AI), YOLO mode
2867-
2868-
Auggie CLI Augment Code CLI Standard ACP support
2869-
2870-
Codex OpenAI Codex Full ACP implementation
2871-
-----------------------------------------------------------------------
28722860

28732861
CLIENT CAPABILITIES
28742862

@@ -3902,8 +3890,7 @@ The plugin allows you to run tools on autopilot, with YOLO mode. This
39023890
automatically approves any tool use instead of prompting the user, disables any
39033891
diffs, submits errors and success messages and automatically saves any buffers
39043892
that tools may have edited. In the chat buffer, the keymap `gty` will toggle
3905-
YOLO mode on/off. Alternatively, set the global variable
3906-
`vim.g.codecompanion_yolo_mode` to enable this or set it to `nil` to undo this.
3893+
YOLO mode on/off.
39073894

39083895

39093896
SECURITY AND APPROVALS ~
@@ -4670,7 +4657,7 @@ These handlers manage tool/function calling:
46704657
as a great reference to understand how they’re working with the output of the
46714658
API
46724659

4673-
OPENAIS API OUTPUT
4660+
OPENAI€�S API OUTPUT
46744661

46754662
If we reference the OpenAI documentation
46764663
<https://platform.openai.com/docs/guides/text-generation/chat-completions-api>
@@ -5324,7 +5311,8 @@ Let’s breakdown the prompts in that workflow:
53245311
opts = { auto_submit = false },
53255312
content = function()
53265313
-- Leverage YOLO mode which disables the requirement of approvals and automatically saves any edited buffer
5327-
vim.g.codecompanion_yolo_mode = true
5314+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
5315+
approvals:toggle_yolo_mode()
53285316

53295317
-- Some clear instructions for the LLM to follow
53305318
return [[### Instructions
@@ -6400,7 +6388,7 @@ tool to function. In the case of Anthropic, we insert additional headers.
64006388
<
64016389

64026390
Some adapter tools can be a `hybrid` in terms of their implementation. That is,
6403-
they’re an adapter tool that requires a client-side component (i.e. a
6391+
they’re an adapter tool that requires a client-side component (i.e.a
64046392
built-in tool). This is the case for the
64056393
|codecompanion-usage-chat-buffer-tools-memory| tool from Anthropic. To allow
64066394
for this, ensure that the tool definition in `available_tools` has

doc/extending/agentic-workflows.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ prompts = {
3131
opts = { auto_submit = false },
3232
content = function()
3333
-- Leverage YOLO mode which disables the requirement of approvals and automatically saves any edited buffer
34-
vim.g.codecompanion_yolo_mode = true
34+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
35+
approvals:toggle_yolo_mode()
3536

3637
-- Some clear instructions for the LLM to follow
3738
return [[### Instructions

doc/usage/chat-buffer/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ In the `openai_responses` adapter, the following tools are available:
338338

339339
### YOLO mode
340340

341-
The plugin allows you to run tools on autopilot, with YOLO mode. This automatically approves any tool use instead of prompting the user, disables any diffs, submits errors and success messages and automatically saves any buffers that tools may have edited. In the chat buffer, the keymap `gty` will toggle YOLO mode on/off. Alternatively, set the global variable `vim.g.codecompanion_yolo_mode` to enable this or set it to `nil` to undo this.
341+
The plugin allows you to run tools on autopilot, with YOLO mode. This automatically approves any tool use instead of prompting the user, disables any diffs, submits errors and success messages and automatically saves any buffers that tools may have edited. In the chat buffer, the keymap `gty` will toggle YOLO mode on/off.
342342

343343
## Security and Approvals
344344

lua/codecompanion/interactions/chat/helpers/diff.lua

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
12
local config = require("codecompanion.config")
23
local keymaps = require("codecompanion.utils.keymaps")
34
local log = require("codecompanion.utils.log")
@@ -303,7 +304,7 @@ end
303304
---Create a diff for a buffer or file and set up keymaps
304305
---@param bufnr_or_path number|string The buffer number or file path to create diff for
305306
---@param diff_id number|string Unique identifier for this diff
306-
---@param opts? { original_content: string[], set_keymaps?: boolean }
307+
---@param opts? { chat_bufnr?: number, original_content: string[], set_keymaps?: boolean }
307308
---@return table|nil diff The diff object, or nil if no diff was created
308309
function M.create(bufnr_or_path, diff_id, opts)
309310
opts = opts or {}
@@ -313,26 +314,23 @@ function M.create(bufnr_or_path, diff_id, opts)
313314

314315
log:debug("[builtin::helpers::diff::create] Called - diff_id=%s", tostring(diff_id))
315316

316-
if vim.g.codecompanion_yolo_mode or not config.display.diff.enabled then
317+
if approvals:is_approved(opts.chat_bufnr) or not config.display.diff.enabled then
317318
return nil
318319
end
319320

320321
local provider = config.display.diff.provider
321322
local ok, diff_module = pcall(require, "codecompanion.providers.diff." .. provider)
322323
if not ok then
323-
log:error("[builtin::helpers::diff::create] Failed to load provider '%s'", provider)
324-
return nil
324+
return log:error("[builtin::helpers::diff::create] Failed to load provider '%s'", provider)
325325
end
326326

327327
local bufnr, winnr = M.open_buffer_and_window(bufnr_or_path)
328328
if not bufnr then
329-
log:warn("[builtin::helpers::diff::create] Failed to open buffer/file")
330-
return nil
329+
return log:warn("[builtin::helpers::diff::create] Failed to open buffer/file")
331330
end
332331

333332
if vim.bo[bufnr].buftype == "terminal" then
334-
log:debug("[builtin::helpers::diff::create] Skipping diff - terminal buffer")
335-
return nil
333+
return log:debug("[builtin::helpers::diff::create] Skipping diff - terminal buffer")
336334
end
337335

338336
local provider_config = config.display.diff.provider_opts[provider] or {}
@@ -386,24 +384,4 @@ function M.setup_keymaps(diff, opts)
386384
:set()
387385
end
388386

389-
---Check if a diff should be created for this context
390-
---@param bufnr number
391-
---@return boolean should_create
392-
---@return string|nil reason Why diff creation was skipped
393-
function M.should_create(bufnr)
394-
if vim.g.codecompanion_yolo_mode then
395-
return false, "yolo_mode"
396-
end
397-
398-
if not config.display.diff.enabled then
399-
return false, "diff_disabled"
400-
end
401-
402-
if vim.bo[bufnr].buftype == "terminal" then
403-
return false, "terminal_buffer"
404-
end
405-
406-
return true, nil
407-
end
408-
409387
return M

lua/codecompanion/interactions/chat/helpers/wait.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ local M = {}
1010
---@param id string|number Unique identifier for the decision context
1111
---@param events table Name of events to wait for. First one is considered "accept"
1212
---@param callback function Callback to execute when decision is made
13-
---@param opts? table Optional configuration
13+
---@param opts? { chat_bufnr?: number, notify?: string, sub_text?: string, timeout?: number }
1414
function M.for_decision(id, events, callback, opts)
1515
opts = opts or {}
1616

17-
-- Auto-approve if in YOLO mode
18-
-- Generally, most tools will avoid us reaching this point, but it's a good fallback
19-
if vim.g.codecompanion_yolo_mode then
17+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
18+
if approvals:is_approved(opts.chat_bufnr) then
2019
return callback({ accepted = true, auto_approved = true })
2120
end
2221

lua/codecompanion/interactions/chat/tools/approvals.lua

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ local approved = {}
3333
---@class CodeCompanion.Tools.Approvals
3434
local Approvals = {}
3535

36-
---Add an approval to the cache
36+
---Always approve a given tool
3737
---@param bufnr number
3838
---@param args { tool_name: string }
39-
function Approvals:add(bufnr, args)
39+
function Approvals:always(bufnr, args)
4040
if not args or not args.tool_name then
4141
return
4242
end
@@ -64,10 +64,10 @@ function Approvals:is_approved(bufnr, args)
6464
end
6565

6666
local config = require("codecompanion.config")
67-
local tool_cfg = config.tools and config.tools[args.tool_name]
68-
if tool_cfg and tool_cfg.args then
67+
local tool_cfg = config.interactions.chat.tools and config.interactions.chat.tools[args.tool_name]
68+
if tool_cfg and tool_cfg.opts then
6969
-- Allow users to designate certain tools as not allowed in yolo mode
70-
if tool_cfg.args.allowed_in_yolo_mode == false then
70+
if tool_cfg.opts.allowed_in_yolo_mode == false then
7171
return false
7272
end
7373
end
@@ -78,9 +78,13 @@ function Approvals:is_approved(bufnr, args)
7878
end
7979

8080
---Toggle yolo mode for a given chat buffer
81-
---@param bufnr number
81+
---@param bufnr? number
8282
---@return nil
8383
function Approvals:toggle_yolo_mode(bufnr)
84+
if not bufnr or bufnr == 0 then
85+
bufnr = vim.api.nvim_get_current_buf()
86+
end
87+
8488
if not approved[bufnr] then
8589
approved[bufnr] = {}
8690
end
@@ -99,4 +103,10 @@ function Approvals:reset(bufnr)
99103
approved[bufnr] = nil
100104
end
101105

106+
---List all approvals
107+
---@return table<string, string[]>
108+
function Approvals.list()
109+
return approved
110+
end
111+
102112
return Approvals

lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ local function edit_file(action, chat_bufnr, output_handler, opts)
794794
local diff_id = math.random(10000000)
795795
local original_lines = vim.split(current_content, "\n", { plain = true })
796796
local should_diff = diff.create(path, diff_id, {
797+
chat_bufnr = chat_bufnr,
797798
original_content = original_lines,
798799
})
799800

@@ -889,6 +890,7 @@ local function edit_buffer(bufnr, chat_bufnr, action, output_handler, opts)
889890
api.nvim_buf_set_lines(bufnr, 0, -1, false, final_lines)
890891

891892
local should_diff = diff.create(bufnr, diff_id, {
893+
chat_bufnr = chat_bufnr,
892894
original_content = original_content,
893895
})
894896

lua/codecompanion/interactions/chat/tools/orchestrator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function Orchestrator:setup_next_tool(input)
283283

284284
if choice == 1 or choice == 2 then
285285
if choice == 1 then
286-
Approvals:add(self.tools.bufnr, { tool_name = self.tool.name })
286+
Approvals:always(self.tools.bufnr, { tool_name = self.tool.name })
287287
end
288288
return self:execute_tool({ cmd = cmd, input = input })
289289
elseif choice == 3 then

lua/codecompanion/interactions/inline/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,10 @@ end
715715
---@return nil
716716
function Inline:start_diff(original_content)
717717
log:debug("[Inline] Starting diff with provider: %s", config.display.diff.provider)
718-
if config.display.diff.enabled == false then
718+
719+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
720+
721+
if approvals:is_approved(self.bufnr) or config.display.diff.enabled == false then
719722
return self:reset()
720723
end
721724

lua/codecompanion/interactions/inline/keymaps.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local config = require("codecompanion.config")
22
local log = require("codecompanion.utils.log")
3-
local utils = require("codecompanion.utils")
43

54
local M = {}
65

@@ -42,13 +41,14 @@ M.reject_change = {
4241
M.always_accept = {
4342
desc = "Accept and enable auto mode",
4443
callback = function(inline)
44+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
45+
approvals:toggle_yolo_mode(inline.bufnr)
46+
4547
if inline.diff then
4648
log:trace("[Inline] Auto-accepting diff for id=%s", tostring(inline.id))
4749
inline.diff:accept()
4850
clear_map(config.interactions.inline.keymaps, inline.diff.bufnr)
4951
end
50-
vim.g.codecompanion_yolo_mode = true
51-
log:trace("[Inline] YOLO mode enabled")
5252
end,
5353
}
5454

0 commit comments

Comments
 (0)