Skip to content

Commit 7cc7f7e

Browse files
committed
wip
1 parent 15eb4c8 commit 7cc7f7e

File tree

6 files changed

+114
-97
lines changed

6 files changed

+114
-97
lines changed

doc/codecompanion.txt

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

33
==============================================================================
44
Table of Contents *codecompanion-table-of-contents*
@@ -1539,72 +1539,29 @@ dependency and want to refresh the tool availability in the chat buffer.
15391539

15401540
APPROVALS
15411541

1542-
Some tools, such as |codecompanion-usage-chat-buffer-tools.html-cmd-runner|,
1543-
require the user to approve any commands before they’re executed. This can be
1544-
changed by altering the config for each tool:
1542+
CodeCompanion allows you to apply safety mechanisms to its built-in tools prior
1543+
to execution.
15451544

1546-
>lua
1547-
require("codecompanion").setup({
1548-
interactions = {
1549-
chat = {
1550-
tools = {
1551-
["cmd_runner"] = {
1552-
opts = {
1553-
require_approval_before = false,
1554-
},
1555-
},
1556-
}
1557-
}
1558-
}
1559-
})
1560-
<
1561-
1562-
You can also force any tool to require your approval by adding in
1563-
`opts.require_approval_before = true`.
15641545

15651546

15661547
AUTO SUBMIT (RECURSION)
15671548

15681549
When a tool executes, it can be useful to automatically send its output back to
15691550
the LLM. This can be achieved by the following options in your configuration:
15701551

1571-
>lua
1572-
require("codecompanion").setup({
1573-
interactions = {
1574-
chat = {
1575-
tools = {
1576-
opts = {
1577-
auto_submit_errors = true, -- Send any errors to the LLM automatically?
1578-
auto_submit_success = true, -- Send any successful output to the LLM automatically?
1579-
},
1580-
}
1581-
}
1582-
}
1583-
})
1584-
<
1552+
`lua {6-7} require("codecompanion").setup({ interactions = { chat = { tools = {
1553+
opts = { auto_submit_errors = true, -- Send any errors to the LLM
1554+
automatically? auto_submit_success = true, -- Send any successful output to the
1555+
LLM automatically? }, } } } })`
15851556

15861557

15871558
DEFAULT TOOLS
15881559

15891560
You can configure the plugin to automatically add tools and tool groups to new
15901561
chat buffers:
15911562

1592-
>lua
1593-
require("codecompanion").setup({
1594-
interactions = {
1595-
chat = {
1596-
tools = {
1597-
opts = {
1598-
default_tools = {
1599-
"my_tool",
1600-
"my_tool_group"
1601-
}
1602-
},
1603-
}
1604-
}
1605-
}
1606-
})
1607-
<
1563+
`lua {6-9} require("codecompanion").setup({ interactions = { chat = { tools = {
1564+
opts = { default_tools = { "my_tool", "my_tool_group" } }, } } } })`
16081565

16091566
This also works for |codecompanion-configuration-extensions|.
16101567

@@ -3881,19 +3838,7 @@ In the `openai_responses` adapter, the following tools are available:
38813838
- `web_search` - Allow models to search the web for the latest information before generating a response.
38823839

38833840

3884-
USEFUL TIPS ~
3885-
3886-
3887-
YOLO MODE
3888-
3889-
The plugin allows you to run tools on autopilot, with YOLO mode. This
3890-
automatically approves any tool use instead of prompting the user, disables any
3891-
diffs, submits errors and success messages and automatically saves any buffers
3892-
that tools may have edited. In the chat buffer, the keymap `gty` will toggle
3893-
YOLO mode on/off.
3894-
3895-
3896-
SECURITY AND APPROVALS ~
3841+
SECURITY ~
38973842

38983843
CodeCompanion takes security very seriously, especially in a world of agentic
38993844
code development. To that end, every effort is made to ensure that LLMs are
@@ -3904,17 +3849,40 @@ is that the LLM can only work within the cwd when executing tools but will
39043849
minimize actions that are hard to recover from
39053850
<https://www.businessinsider.com/replit-ceo-apologizes-ai-coding-tool-delete-company-database-2025-7>.
39063851

3907-
The plugin also puts approvals at the heart of its workflow. Some tools, such
3908-
as the |codecompanion--cmd-runner|, require the user to approve any actions
3909-
before they can be executed. If the tool requires this a `vim.fn.confirm`
3910-
dialog will prompt you for a response. You may also
3911-
|codecompanion-configuration-chat-buffer-approvals| an approval for `any` tool.
39123852

3913-
When using CodeCompanion’s in-built tools, there are three choices:
3853+
APPROVALS
3854+
3855+
3856+
[!NOTE] This applies to CodeCompanion’s built-in tools only. ACP agents have
3857+
their own tools and approval systems.
3858+
In order to give developers the confidence to use tools, CodeCompanion has
3859+
implemented a comprehensive approval system for it’s built-in tools.
3860+
3861+
CodeCompanion segregates tool approvals by chat buffer and by tool. This means
3862+
that if you approve a tool in one chat buffer, it is `not` approved for use
3863+
anywhere else. Similarly, if you approve a tool once, you’ll be prompted to
3864+
approve it again next time it’s executed.
3865+
3866+
When prompted, the user has four options available to them:
3867+
3868+
- **Allow always** - Always allow this tool/cmd to be executed without further prompts
3869+
- **Allow once** - Allow this tool/cmd to be executed this one time
3870+
- **Reject** - Reject the execution of this tool/cmd and provide a reason
3871+
- **Cancel** - Cancel this tool execution and all other pending tool executions
3872+
3873+
Certain tools with potentially destructive capabilities have an additional
3874+
layer of protection. Instead of being approved at a tool level, these are
3875+
approved at a command level. Taking the `cmd_runner` tool as an example. If you
3876+
approve an agent to always run `make format`, if it tries to run `make test`,
3877+
you’ll be prompted to approve that command specifically.
3878+
3879+
3880+
YOLO MODE
39143881

3915-
1. **Approve** - The tool will be executed
3916-
2. **Reject** - The tool will **NOT** be executed
3917-
3. **Cancel** - All tools in the queue will **NOT** be executed
3882+
To bypass the approval system, you can use `gty` in the chat buffer to enable
3883+
YOLO mode. This will automatically approve all tool executions without
3884+
prompting the user. However, note that some tools such as `cmd_runner` and
3885+
`delete_file` are excluded from this.
39183886

39193887

39203888
COMPATIBILITY ~

doc/configuration/chat-buffer.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,31 +372,65 @@ require("codecompanion").setup({
372372

373373
### Approvals
374374

375-
Some tools, such as [cmd_runner](/usage/chat-buffer/tools.html#cmd-runner), require the user to approve any commands before they're executed. This can be changed by altering the config for each tool:
375+
CodeCompanion allows you to apply safety mechanisms to its built-in tools prior to execution.
376376

377-
```lua
377+
::: code-group
378+
379+
```lua [Require Approval] {7}
378380
require("codecompanion").setup({
379381
interactions = {
380382
chat = {
381383
tools = {
382384
["cmd_runner"] = {
383385
opts = {
384-
require_approval_before = false,
386+
require_approval_before = true,
385387
},
386388
},
387-
}
388-
}
389-
}
389+
},
390+
},
391+
},
392+
})
393+
```
394+
395+
```lua [Require Cmd Approval] {7}
396+
require("codecompanion").setup({
397+
interactions = {
398+
chat = {
399+
tools = {
400+
["cmd_runner"] = {
401+
opts = {
402+
require_cmd_approval = true,
403+
},
404+
},
405+
},
406+
},
407+
},
408+
})
409+
```
410+
411+
```lua [No YOLO'ing] {7}
412+
require("codecompanion").setup({
413+
interactions = {
414+
chat = {
415+
tools = {
416+
["cmd_runner"] = {
417+
opts = {
418+
allowed_in_yolo_mode = false,
419+
},
420+
},
421+
},
422+
},
423+
},
390424
})
391425
```
392426

393-
You can also force any tool to require your approval by adding in `opts.require_approval_before = true`.
427+
:::
394428

395429
### Auto Submit (Recursion)
396430

397431
When a tool executes, it can be useful to automatically send its output back to the LLM. This can be achieved by the following options in your configuration:
398432

399-
```lua
433+
```lua {6-7}
400434
require("codecompanion").setup({
401435
interactions = {
402436
chat = {
@@ -415,7 +449,7 @@ require("codecompanion").setup({
415449

416450
You can configure the plugin to automatically add tools and tool groups to new chat buffers:
417451

418-
```lua
452+
```lua {6-9}
419453
require("codecompanion").setup({
420454
interactions = {
421455
chat = {

doc/usage/chat-buffer/tools.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,31 @@ In the `openai_responses` adapter, the following tools are available:
334334

335335
- `web_search` - Allow models to search the web for the latest information before generating a response.
336336

337-
## Useful Tips
337+
## Security
338338

339-
### YOLO mode
339+
CodeCompanion takes security very seriously, especially in a world of agentic code development. To that end, every effort is made to ensure that LLMs are only given the information that they need to execute a tool successfully. CodeCompanion will endeavour to make sure that the full disk path to your current working directory (cwd) in Neovim is never shared. The impact of this is that the LLM can only work within the cwd when executing tools but will minimize actions that are hard to [recover from](https://www.businessinsider.com/replit-ceo-apologizes-ai-coding-tool-delete-company-database-2025-7).
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.
341+
### Approvals
342342

343-
## Security and Approvals
343+
> [!NOTE]
344+
> This applies to CodeCompanion's built-in tools only. ACP agents have their own tools and approval systems.
344345
345-
CodeCompanion takes security very seriously, especially in a world of agentic code development. To that end, every effort is made to ensure that LLMs are only given the information that they need to execute a tool successfully. CodeCompanion will endeavour to make sure that the full disk path to your current working directory (cwd) in Neovim is never shared. The impact of this is that the LLM can only work within the cwd when executing tools but will minimize actions that are hard to [recover from](https://www.businessinsider.com/replit-ceo-apologizes-ai-coding-tool-delete-company-database-2025-7).
346+
In order to give developers the confidence to use tools, CodeCompanion has implemented a comprehensive approval system for it's built-in tools.
346347

347-
The plugin also puts approvals at the heart of its workflow. Some tools, such as the [@cmd_runner](#cmd-runner), require the user to approve any actions before they can be executed. If the tool requires this a `vim.fn.confirm` dialog will prompt you for a response. You may also [enforce](/configuration/chat-buffer#approvals) an approval for _any_ tool.
348+
CodeCompanion segregates tool approvals by chat buffer and by tool. This means that if you approve a tool in one chat buffer, it is _not_ approved for use anywhere else. Similarly, if you approve a tool once, you'll be prompted to approve it again next time it's executed.
348349

349-
When using CodeCompanion's in-built tools, there are three choices:
350+
When prompted, the user has four options available to them:
351+
352+
- **Allow always** - Always allow this tool/cmd to be executed without further prompts
353+
- **Allow once** - Allow this tool/cmd to be executed this one time
354+
- **Reject** - Reject the execution of this tool/cmd and provide a reason
355+
- **Cancel** - Cancel this tool execution and all other pending tool executions
356+
357+
Certain tools with potentially destructive capabilities have an additional layer of protection. Instead of being approved at a tool level, these are approved at a command level. Taking the `cmd_runner` tool as an example. If you approve an agent to always run `make format`, if it tries to run `make test`, you'll be prompted to approve that command specifically.
358+
359+
### YOLO mode
350360

351-
1. **Approve** - The tool will be executed
352-
2. **Reject** - The tool will **NOT** be executed
353-
3. **Cancel** - All tools in the queue will **NOT** be executed
361+
To bypass the approval system, you can use `gty` in the chat buffer to enable YOLO mode. This will automatically approve all tool executions without prompting the user. However, note that some tools such as `cmd_runner` and `delete_file` are excluded from this.
354362

355363
## Compatibility
356364

lua/codecompanion/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ local defaults = {
157157
callback = "interactions.chat.tools.builtin.delete_file",
158158
description = "Delete a file in the current working directory",
159159
opts = {
160+
allowed_in_yolo_mode = false,
160161
require_approval_before = true,
161162
require_cmd_approval = true,
162163
},

lua/codecompanion/interactions/chat/keymaps/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ M.yolo_mode = {
578578
desc = "Toggle YOLO mode",
579579
callback = function(chat)
580580
local approvals = require("codecompanion.interactions.chat.tools.approvals")
581-
approvals:toggle_yolo_mode(chat.bufnr)
581+
local status = approvals:toggle_yolo_mode(chat.bufnr)
582+
if status then
583+
return utils.notify("YOLO mode enabled!", vim.log.levels.INFO)
584+
end
585+
return utils.notify("YOLO mode disabled!", vim.log.levels.INFO)
582586
end,
583587
}
584588

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ end
132132

133133
---Toggle yolo mode for a given chat buffer
134134
---@param bufnr? number
135-
---@return nil
135+
---@return boolean
136136
function Approvals:toggle_yolo_mode(bufnr)
137137
if not bufnr or bufnr == 0 then
138138
bufnr = vim.api.nvim_get_current_buf()
@@ -144,9 +144,11 @@ function Approvals:toggle_yolo_mode(bufnr)
144144

145145
if approved[bufnr]["yolo_mode"] then
146146
approved[bufnr]["yolo_mode"] = nil
147-
else
148-
approved[bufnr]["yolo_mode"] = true
147+
return false
149148
end
149+
150+
approved[bufnr]["yolo_mode"] = true
151+
return true
150152
end
151153

152154
---Reset the approvals for a given chat buffer

0 commit comments

Comments
 (0)