Skip to content

Commit 15eb4c8

Browse files
committed
wip
1 parent 518a2bf commit 15eb4c8

File tree

9 files changed

+140
-62
lines changed

9 files changed

+140
-62
lines changed

lua/codecompanion/config.lua

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ local defaults = {
130130
opts = {
131131
allowed_in_yolo_mode = false,
132132
require_approval_before = true,
133+
require_cmd_approval = true,
133134
},
134135
},
135136
["insert_edit_into_file"] = {
@@ -149,13 +150,15 @@ local defaults = {
149150
description = "Create a file in the current working directory",
150151
opts = {
151152
require_approval_before = true,
153+
require_cmd_approval = true,
152154
},
153155
},
154156
["delete_file"] = {
155157
callback = "interactions.chat.tools.builtin.delete_file",
156158
description = "Delete a file in the current working directory",
157159
opts = {
158160
require_approval_before = true,
161+
require_cmd_approval = true,
159162
},
160163
},
161164
["fetch_webpage"] = {
@@ -170,6 +173,7 @@ local defaults = {
170173
description = "Search for files in the current working directory by glob pattern",
171174
opts = {
172175
max_results = 500,
176+
require_cmd_approval = true,
173177
},
174178
},
175179
["get_changed_files"] = {
@@ -189,6 +193,8 @@ local defaults = {
189193
opts = {
190194
max_results = 100,
191195
respect_gitignore = true,
196+
require_approval_before = true,
197+
require_cmd_approval = true,
192198
},
193199
},
194200
["memory"] = {
@@ -205,6 +211,10 @@ local defaults = {
205211
["read_file"] = {
206212
callback = "interactions.chat.tools.builtin.read_file",
207213
description = "Read a file in the current working directory",
214+
opts = {
215+
require_approval_before = true,
216+
require_cmd_approval = true,
217+
},
208218
},
209219
["web_search"] = {
210220
callback = "interactions.chat.tools.builtin.web_search",
@@ -464,7 +474,7 @@ If you are providing code changes, use the insert_edit_into_file tool (if availa
464474
modes = { i = "<C-_>" },
465475
index = 1,
466476
callback = "keymaps.completion",
467-
description = "Completion menu",
477+
description = "[Chat] Completion menu",
468478
},
469479
send = {
470480
modes = {
@@ -473,13 +483,13 @@ If you are providing code changes, use the insert_edit_into_file tool (if availa
473483
},
474484
index = 2,
475485
callback = "keymaps.send",
476-
description = "Send message",
486+
description = "[Request] Send response",
477487
},
478488
regenerate = {
479489
modes = { n = "gr" },
480490
index = 3,
481491
callback = "keymaps.regenerate",
482-
description = "Regenerate last response",
492+
description = "[Request] Regenerate",
483493
},
484494
close = {
485495
modes = {
@@ -488,121 +498,127 @@ If you are providing code changes, use the insert_edit_into_file tool (if availa
488498
},
489499
index = 4,
490500
callback = "keymaps.close",
491-
description = "Close chat",
501+
description = "[Chat] Close",
492502
},
493503
stop = {
494504
modes = { n = "q" },
495505
index = 5,
496506
callback = "keymaps.stop",
497-
description = "Stop request",
507+
description = "[Request] Stop",
498508
},
499509
clear = {
500510
modes = { n = "gx" },
501511
index = 6,
502512
callback = "keymaps.clear",
503-
description = "Clear chat",
513+
description = "[Chat] Clear",
504514
},
505515
codeblock = {
506516
modes = { n = "gc" },
507517
index = 7,
508518
callback = "keymaps.codeblock",
509-
description = "Insert codeblock",
519+
description = "[Chat] Insert codeblock",
510520
},
511521
yank_code = {
512522
modes = { n = "gy" },
513523
index = 8,
514524
callback = "keymaps.yank_code",
515-
description = "Yank code",
525+
description = "[Chat] Yank code",
516526
},
517527
buffer_sync_all = {
518528
modes = { n = "gba" },
519529
index = 9,
520530
callback = "keymaps.buffer_sync_all",
521-
description = "Toggle the syncing of the entire buffer",
531+
description = "[Chat] Toggle buffer syncing",
522532
},
523533
buffer_sync_diff = {
524534
modes = { n = "gbd" },
525535
index = 10,
526536
callback = "keymaps.buffer_sync_diff",
527-
description = "Toggle the syncing of the buffer to share it's diffs",
537+
description = "[Chat] Toggle buffer diff syncing",
528538
},
529539
next_chat = {
530540
modes = { n = "}" },
531541
index = 11,
532542
callback = "keymaps.next_chat",
533-
description = "Next chat",
543+
description = "[Nav] Next chat",
534544
},
535545
previous_chat = {
536546
modes = { n = "{" },
537547
index = 12,
538548
callback = "keymaps.previous_chat",
539-
description = "Previous chat",
549+
description = "[Nav] Previous chat",
540550
},
541551
next_header = {
542552
modes = { n = "]]" },
543553
index = 13,
544554
callback = "keymaps.next_header",
545-
description = "Next header",
555+
description = "[Nav] Next header",
546556
},
547557
previous_header = {
548558
modes = { n = "[[" },
549559
index = 14,
550560
callback = "keymaps.previous_header",
551-
description = "Previous header",
561+
description = "[Nav] Previous header",
552562
},
553563
change_adapter = {
554564
modes = { n = "ga" },
555565
index = 15,
556566
callback = "keymaps.change_adapter",
557-
description = "Change adapter",
567+
description = "[Adapter] Change adapter and model",
558568
},
559569
fold_code = {
560570
modes = { n = "gf" },
561571
index = 15,
562572
callback = "keymaps.fold_code",
563-
description = "Fold code",
573+
description = "[Chat] Fold code",
564574
},
565575
debug = {
566576
modes = { n = "gd" },
567577
index = 16,
568578
callback = "keymaps.debug",
569-
description = "View debug info",
579+
description = "[Chat] View debug info",
570580
},
571581
system_prompt = {
572582
modes = { n = "gs" },
573583
index = 17,
574584
callback = "keymaps.toggle_system_prompt",
575-
description = "Toggle system prompt",
585+
description = "[Chat] Toggle system prompt",
576586
},
577587
rules = {
578588
modes = { n = "gM" },
579589
index = 18,
580590
callback = "keymaps.clear_rules",
581-
description = "Clear Rules",
591+
description = "[Chat] Clear Rules",
592+
},
593+
clear_approvals = {
594+
modes = { n = "gtx" },
595+
index = 19,
596+
callback = "keymaps.clear_approvals",
597+
description = "[Tools] Clear approvals",
582598
},
583599
yolo_mode = {
584600
modes = { n = "gty" },
585-
index = 19,
601+
index = 20,
586602
callback = "keymaps.yolo_mode",
587-
description = "YOLO mode toggle",
603+
description = "[Tools] Toggle YOLO mode",
588604
},
589605
goto_file_under_cursor = {
590606
modes = { n = "gR" },
591-
index = 20,
607+
index = 21,
592608
callback = "keymaps.goto_file_under_cursor",
593-
description = "Open file under cursor",
609+
description = "[Chat] Open file under cursor",
594610
},
595611
copilot_stats = {
596612
modes = { n = "gS" },
597-
index = 21,
613+
index = 22,
598614
callback = "keymaps.copilot_stats",
599-
description = "Show Copilot statistics",
615+
description = "[Adapter] Copilot statistics",
600616
},
601617
super_diff = {
602618
modes = { n = "gD" },
603-
index = 22,
619+
index = 23,
604620
callback = "keymaps.super_diff",
605-
description = "Show Super Diff",
621+
description = "[Tools] Show Super Diff",
606622
},
607623
-- Keymaps for ACP permission requests
608624
_acp_allow_always = {
@@ -662,32 +678,32 @@ The user is working on a %s machine. Please respond with system specific command
662678
inline = {
663679
adapter = "copilot",
664680
keymaps = {
665-
accept_change = {
666-
modes = { n = "gda" },
667-
opts = { nowait = true, noremap = true },
681+
always_accept = {
682+
callback = "keymaps.always_accept",
683+
description = "Always accept changes in this buffer",
668684
index = 1,
685+
modes = { n = "gdy" },
686+
opts = { nowait = true },
687+
},
688+
accept_change = {
669689
callback = "keymaps.accept_change",
670690
description = "Accept change",
691+
index = 2,
692+
modes = { n = "gda" },
693+
opts = { nowait = true, noremap = true },
671694
},
672695
reject_change = {
673-
modes = { n = "gdr" },
674-
opts = { nowait = true, noremap = true },
675-
index = 2,
676696
callback = "keymaps.reject_change",
677697
description = "Reject change",
678-
},
679-
always_accept = {
680-
modes = { n = "gdy" },
681-
opts = { nowait = true },
682698
index = 3,
683-
callback = "keymaps.always_accept",
684-
description = "Accept and enable auto mode",
699+
modes = { n = "gdr" },
700+
opts = { nowait = true, noremap = true },
685701
},
686702
stop = {
687-
modes = { n = "q" },
688-
index = 4,
689703
callback = "keymaps.stop",
690704
description = "Stop request",
705+
index = 4,
706+
modes = { n = "q" },
691707
},
692708
},
693709
variables = {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,15 @@ M.clear_rules = {
565565
end,
566566
}
567567

568+
M.clear_approvals = {
569+
desc = "Clear approvals in the current buffer",
570+
callback = function(chat)
571+
local approvals = require("codecompanion.interactions.chat.tools.approvals")
572+
approvals:reset(chat.bufnr)
573+
return utils.notify("Cleared the approvals", vim.log.levels.INFO)
574+
end,
575+
}
576+
568577
M.yolo_mode = {
569578
desc = "Toggle YOLO mode",
570579
callback = function(chat)

lua/codecompanion/interactions/chat/tools/builtin/cmd_runner.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ return {
104104
---@param self CodeCompanion.Tool.CmdRunner
105105
---@param args { tools: CodeCompanion.Tools }
106106
---@return string
107-
cmd = function(self, args)
107+
cmd_string = function(self, args)
108108
return self.args.cmd
109109
end,
110+
110111
---Prompt the user to approve the execution of the command
111112
---@param self CodeCompanion.Tool.CmdRunner
112113
---@param tool CodeCompanion.Tools

lua/codecompanion/interactions/chat/tools/builtin/create_file.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ local log = require("codecompanion.utils.log")
44

55
local fmt = string.format
66

7+
---Modify the path to be relative to the current working directory
8+
---@param path string
9+
---@return string
10+
local function modify_path(path)
11+
return vim.fn.fnamemodify(path, ":.")
12+
end
13+
714
---Create a file and the surrounding folders
815
---@param action {filepath: string, content: string} The action containing the filepath and content
916
---@return {status: "success"|"error", data: string}
@@ -132,14 +139,20 @@ return {
132139
end,
133140
},
134141
output = {
142+
---Returns the command that will be executed
143+
---@param self CodeCompanion.Tool.CreateFile
144+
---@param args { tools: CodeCompanion.Tools }
145+
---@return string
146+
cmd_string = function(self, args)
147+
return modify_path(self.args.filepath)
148+
end,
149+
135150
---The message which is shared with the user when asking for their approval
136151
---@param self CodeCompanion.Tools.Tool
137152
---@param tools CodeCompanion.Tools
138153
---@return nil|string
139154
prompt = function(self, tools)
140-
local args = self.args
141-
local filepath = vim.fn.fnamemodify(args.filepath, ":.")
142-
return fmt("Create a file at %s?", filepath)
155+
return fmt("Create a file at `%s`?", modify_path(self.args.filepath))
143156
end,
144157

145158
---@param self CodeCompanion.Tool.CreateFile

lua/codecompanion/interactions/chat/tools/builtin/delete_file.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ local log = require("codecompanion.utils.log")
33

44
local fmt = string.format
55

6+
---Modify the path to be relative to the current working directory
7+
---@param path string
8+
---@return string
9+
local function modify_path(path)
10+
return vim.fn.fnamemodify(path, ":.")
11+
end
12+
613
---Delete a file
714
---@param action {filepath: string} The action containing the filepath
815
---@return {status: "success"|"error", data: string}
@@ -79,14 +86,20 @@ return {
7986
end,
8087
},
8188
output = {
89+
---Returns the command that will be executed
90+
---@param self CodeCompanion.Tool.DeleteFile
91+
---@param args { tools: CodeCompanion.Tools }
92+
---@return string
93+
cmd_string = function(self, args)
94+
return modify_path(self.args.filepath)
95+
end,
96+
8297
---The message which is shared with the user when asking for their approval
8398
---@param self CodeCompanion.Tools.Tool
8499
---@param tools CodeCompanion.Tools
85100
---@return nil|string
86101
prompt = function(self, tools)
87-
local args = self.args
88-
local filepath = vim.fn.fnamemodify(args.filepath, ":.")
89-
return fmt("Delete the file at %s?", filepath)
102+
return fmt("Delete the file at `%s`?", modify_path(self.args.filepath))
90103
end,
91104

92105
---@param self CodeCompanion.Tool.DeleteFile

0 commit comments

Comments
 (0)