-
-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathconfig.lua
More file actions
1387 lines (1327 loc) · 47.9 KB
/
config.lua
File metadata and controls
1387 lines (1327 loc) · 47.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local providers = require("codecompanion.providers")
local ui_utils = require("codecompanion.utils.ui")
local fmt = string.format
local constants = {
LLM_ROLE = "llm",
USER_ROLE = "user",
SYSTEM_ROLE = "system",
}
local defaults = {
adapters = {
http = {
anthropic = "anthropic",
azure_openai = "azure_openai",
copilot = "copilot",
deepseek = "deepseek",
gemini = "gemini",
githubmodels = "githubmodels",
huggingface = "huggingface",
novita = "novita",
mistral = "mistral",
ollama = "ollama",
openai = "openai",
openai_responses = "openai_responses",
xai = "xai",
jina = "jina",
tavily = "tavily",
opts = {
allow_insecure = false, -- Allow insecure connections?
cache_models_for = 1800, -- Cache adapter models for this long (seconds)
proxy = nil, -- [protocol://]host[:port] e.g. socks5://127.0.0.1:9999
show_presets = true, -- Show preset adapters
show_model_choices = true, -- Show model choices when changing adapter
},
},
acp = {
auggie_cli = "auggie_cli",
cagent = "cagent",
claude_code = "claude_code",
cline_cli = "cline_cli",
codex = "codex",
cursor_cli = "cursor_cli",
copilot_acp = "copilot_acp",
gemini_cli = "gemini_cli",
goose = "goose",
kimi_cli = "kimi_cli",
kiro = "kiro",
mistral_vibe = "mistral_vibe",
opencode = "opencode",
opts = {
show_presets = true,
},
},
opts = {
cmd_timeout = 20e3, -- Timeout for commands that resolve env variables (milliseconds)
},
},
constants = constants,
interactions = {
opts = {
date_format = "%A, %d %B %Y", -- The date format to use in system prompts
watcher = {
enabled = true, -- Reload buffers when an agent modifies files on disk
debounce = 500, -- Debounce time in milliseconds
},
},
-- BACKGROUND INTERACTION -------------------------------------------------
background = {
adapter = {
name = "copilot",
model = "gpt-4.1",
},
-- Callbacks within the plugin that you can attach background actions to
chat = {
callbacks = {
["on_ready"] = {
actions = {
"interactions.background.builtin.chat_make_title",
},
enabled = true,
},
["on_checkpoint"] = {
-- actions = {
-- "interactions.background.builtin.compact",
-- },
enabled = true,
},
},
opts = {
enabled = false, -- Enable ALL background chat interactions?
},
},
},
-- CHAT INTERACTION -------------------------------------------------------
chat = {
adapter = "copilot",
roles = {
---The header name for the LLM's messages
---@type string|fun(adapter: CodeCompanion.HTTPAdapter|CodeCompanion.ACPAdapter): string
llm = function(adapter)
return "CodeCompanion (" .. adapter.formatted_name .. ")"
end,
---The header name for your messages
---@type string
user = "Me",
},
tools = {
groups = {
["agent"] = {
description = "Agent - Can run code, edit code and modify files on your behalf",
system_prompt = function(group, ctx)
return string.format(
[[<instructions>
You are an automated coding agent with expert-level knowledge across many programming languages and frameworks.
The user will ask a question or ask you to perform a task. Use the available tools to gather context and take actions.
If you can infer the project type from the user's query or context, keep it in mind when making changes.
If the user wants you to implement a feature without specifying files, break the request into smaller concepts and think about the kinds of files you need for each.
Call multiple tools if you aren't sure which is relevant. Call tools repeatedly until the task is complete — don't give up unless the request truly cannot be fulfilled.
Gather context first rather than making assumptions. Think creatively and explore the workspace to make a complete fix.
Don't repeat yourself after a tool call — pick up where you left off.
Don't print terminal commands in a code block unless the user asked for it.
You don't need to read a file already provided in context.
</instructions>
<toolUseInstructions>
Follow the JSON schema carefully and include ALL required properties.
Always output valid JSON when using a tool.
Use tools to take actions rather than asking the user to do it manually.
If you say you'll take an action, go ahead and do it.
Never say the name of a tool to a user — e.g. say "I'll edit the file" not "I'll use the insert_edit_into_file tool".
Prefer calling multiple tools in parallel when possible.
Use file paths given by the user or by tool output.
</toolUseInstructions>
<outputFormatting>
Use proper Markdown formatting. Wrap filenames and symbols in backticks.
Code block examples must use four backticks with the language ID.
If you are providing code changes, use the insert_edit_into_file tool (if available) instead of printing a code block.
</outputFormatting>
<additionalContext>
All non-code text responses must be written in the %s language.
The user's current working directory is %s.
The current date is %s.
The user's Neovim version is %s.
The user is working on a %s machine. Please respond with system specific commands if applicable.
</additionalContext>]],
ctx.language,
ctx.cwd,
ctx.date,
ctx.nvim_version,
ctx.os
)
end,
tools = {
"ask_questions",
"create_file",
"delete_file",
"file_search",
"get_changed_files",
"get_diagnostics",
"grep_search",
"insert_edit_into_file",
"read_file",
"run_command",
"apply_patch",
},
opts = {
collapse_tools = true,
ignore_system_prompt = true,
ignore_tool_system_prompt = true,
},
},
["files"] = {
description = "Tools related to creating, reading and editing files",
prompt = "I'm giving you access to ${tools} to help you perform file operations",
tools = {
"create_file",
"delete_file",
"file_search",
"get_changed_files",
"grep_search",
"insert_edit_into_file",
"read_file",
"apply_patch",
},
opts = {
collapse_tools = true,
},
},
},
-- Tools
["ask_questions"] = {
path = "interactions.chat.tools.builtin.ask_questions",
description = "Ask the user questions to clarify requirements or validate assumptions",
visible = false,
},
["create_file"] = {
path = "interactions.chat.tools.builtin.create_file",
description = "Create a file in the current working directory",
opts = {
require_approval_before = true,
},
},
["delete_file"] = {
path = "interactions.chat.tools.builtin.delete_file",
description = "Delete a file in the current working directory",
opts = {
allowed_in_yolo_mode = false,
require_approval_before = true,
},
},
["fetch_webpage"] = {
path = "interactions.chat.tools.builtin.fetch_webpage",
description = "Fetches content from a webpage",
opts = {
adapter = "jina",
},
},
["file_search"] = {
path = "interactions.chat.tools.builtin.file_search",
description = "Search for files in the current working directory by glob pattern",
opts = {
max_results = 500,
},
},
["get_changed_files"] = {
path = "interactions.chat.tools.builtin.get_changed_files",
description = "Get git diffs of current file changes in a git repository",
opts = {
max_lines = 1000,
},
},
["get_diagnostics"] = {
path = "interactions.chat.tools.builtin.get_diagnostics",
description = "Get LSP diagnostics for a given file",
},
["grep_search"] = {
path = "interactions.chat.tools.builtin.grep_search",
enabled = function()
-- Currently this tool only supports ripgrep
return vim.fn.executable("rg") == 1
end,
description = "Search for text in the current working directory",
opts = {
max_results = 100,
respect_gitignore = true,
require_approval_before = true,
},
},
["insert_edit_into_file"] = {
path = "interactions.chat.tools.builtin.insert_edit_into_file",
description = "Robustly edit existing files with multiple automatic fallback interactions",
opts = {
require_approval_before = { -- Require approval before the tool is executed?
buffer = false, -- For editing buffers in Neovim
file = false, -- For editing files in the current working directory
},
require_confirmation_after = true, -- Require confirmation from the user before accepting the edit?
file_size_limit_mb = 2, -- Maximum file size in MB
},
},
["memory"] = {
path = "interactions.chat.tools.builtin.memory",
description = "The memory tool enables LLMs to store and retrieve information across conversations through a memory file directory",
opts = {
require_approval_before = true,
whitelist = {}, -- e.g. { { path = "/absolute/path", as = "/alias" } }
},
},
["apply_patch"] = {
path = "interactions.chat.tools.builtin.apply_patch",
description = "Apply a structured patch to the codebase to add, delete, or update files.",
opts = {
require_approval_before = true,
},
},
["read_file"] = {
path = "interactions.chat.tools.builtin.read_file",
description = "Read a file in the current working directory",
opts = {
require_approval_before = true,
},
},
["run_command"] = {
path = "interactions.chat.tools.builtin.run_command",
description = "Run shell commands initiated by the LLM",
opts = {
allowed_in_yolo_mode = false,
require_approval_before = true,
require_cmd_approval = true,
},
},
["web_search"] = {
path = "interactions.chat.tools.builtin.web_search",
description = "Search the web for information",
opts = {
adapter = "tavily", -- tavily
opts = {
-- Tavily options
search_depth = "advanced",
topic = "general",
chunks_per_source = 3,
max_results = 5,
},
},
},
opts = {
auto_submit_errors = true, -- Send any errors to the LLM automatically?
auto_submit_success = true, -- Send any successful output to the LLM automatically?
notify_on_approval = true, -- Notify the user when a tool requires approval?,
folds = {
enabled = true, -- Fold tool output in the buffer?
failure_words = { -- Words that indicate an error in the tool output. Used to apply failure highlighting
"cancelled",
"error",
"failed",
"incorrect",
"invalid",
"rejected",
},
},
---Tools and/or groups that are always loaded in a chat buffer
---@type string[]
default_tools = {},
system_prompt = {
enabled = true, -- Enable the tools system prompt?
replace_main_system_prompt = false, -- Replace the main system prompt with the tools system prompt?
---The tool system prompt
---@param args { ctx: CodeCompanion.SystemPrompt.Context, tools: string[]} The tools available
---@return string
prompt = function(args)
return [[<instructions>
You are a highly sophisticated automated coding agent with expert-level knowledge across many different programming languages and frameworks.
The user will ask a question, or ask you to perform a task, and it may require lots of research to answer correctly. There is a selection of tools that let you perform actions or retrieve helpful context to answer the user's question.
You will be given some context and attachments along with the user prompt. You can use them if they are relevant to the task, and ignore them if not.
If you can infer the project type (languages, frameworks, and libraries) from the user's query or the context that you have, make sure to keep them in mind when making changes.
If the user wants you to implement a feature and they have not specified the files to edit, first break down the user's request into smaller concepts and think about the kinds of files you need to grasp each concept.
If you aren't sure which tool is relevant, you can call multiple tools. You can call tools repeatedly to take actions or gather as much context as needed until you have completed the task fully. Don't give up unless you are sure the request cannot be fulfilled with the tools you have. It's YOUR RESPONSIBILITY to make sure that you have done all you can to collect necessary context.
Don't make assumptions about the situation - gather context first, then perform the task or answer the question.
Think creatively and explore the workspace in order to make a complete fix.
Don't repeat yourself after a tool call, pick up where you left off.
NEVER print out a codeblock with a terminal command to run unless the user asked for it.
You don't need to read a file if it's already provided in context.
</instructions>
<toolUseInstructions>
When using a tool, follow the json schema very carefully and make sure to include ALL required properties.
Always output valid JSON when using a tool.
If a tool exists to do a task, use the tool instead of asking the user to manually take an action.
If you say that you will take an action, then go ahead and use the tool to do it. No need to ask permission.
Never use a tool that does not exist. Use tools using the proper procedure, DO NOT write out a json codeblock with the tool inputs.
Never say the name of a tool to a user. For example, instead of saying that you'll use the insert_edit_into_file tool, say "I'll edit the file".
If you think running multiple tools can answer the user's question, prefer calling them in parallel whenever possible.
When invoking a tool that takes a file path, always use the file path you have been given by the user or by the output of a tool.
</toolUseInstructions>
<outputFormatting>
Use proper Markdown formatting in your answers. When referring to a filename or symbol in the user's workspace, wrap it in backticks.
Any code block examples must be wrapped in four backticks with the programming language.
<example>
````languageId
// Your code here
````
</example>
The languageId must be the correct identifier for the programming language, e.g. python, javascript, lua, etc.
If you are providing code changes, use the insert_edit_into_file tool (if available to you) to make the changes directly instead of printing out a code block with the changes.
</outputFormatting>]]
end,
},
tool_replacement_message = "the ${tool} tool", -- The message to use when replacing tool names in the chat buffer
},
},
slash_commands = {
["acp_session_options"] = {
path = "interactions.chat.slash_commands.builtin.acp_session_options",
description = "Change ACP session config options like mode and reasoning level",
---@param opts { adapter: CodeCompanion.HTTPAdapter|CodeCompanion.ACPAdapter }
---@return boolean
enabled = function(opts)
if opts.adapter and opts.adapter.type == "acp" then
return true
end
return false
end,
opts = {
contains_code = false,
},
},
["buffer"] = {
path = "interactions.shared.slash_commands.buffer",
description = "Insert open buffers",
opts = {
contains_code = true,
default_params = "diff", -- all|diff
interactions = { "chat", "cli" },
provider = providers.pickers, -- telescope|fzf_lua|mini_pick|snacks|default
},
},
["command"] = {
path = "interactions.chat.slash_commands.builtin.command",
description = "Change the command used to start the ACP adapter",
---@param opts { adapter: CodeCompanion.HTTPAdapter|CodeCompanion.ACPAdapter }
---@return boolean
enabled = function(opts)
if opts.adapter and opts.adapter.type == "acp" then
return true
end
return false
end,
opts = {
contains_code = false,
},
},
["compact"] = {
path = "interactions.chat.slash_commands.builtin.compact",
description = "Clears some of the chat history, keeping a summary in context",
enabled = function(opts)
if opts.adapter and opts.adapter.type == "http" then
return true
end
return false
end,
opts = {
contains_code = false,
},
},
["fetch"] = {
path = "interactions.chat.slash_commands.builtin.fetch",
description = "Insert URL contents",
opts = {
adapter = "jina", -- jina
cache_path = vim.fn.stdpath("data") .. "/codecompanion/urls",
provider = providers.pickers, -- telescope|fzf_lua|mini_pick|snacks|default
},
},
["file"] = {
path = "interactions.shared.slash_commands.file",
description = "Insert a file",
opts = {
contains_code = true,
interactions = { "chat", "cli" },
max_lines = 1000,
provider = providers.pickers, -- telescope|fzf_lua|mini_pick|snacks|default
},
},
["help"] = {
path = "interactions.chat.slash_commands.builtin.help",
description = "Insert content from help tags",
opts = {
contains_code = false,
max_lines = 128, -- Maximum amount of lines to of the help file to send (NOTE: Each vimdoc line is typically 10 tokens)
provider = providers.help, -- telescope|fzf_lua|mini_pick|snacks
},
},
["image"] = {
path = "interactions.chat.slash_commands.builtin.image",
description = "Insert an image",
---@param opts { adapter: CodeCompanion.HTTPAdapter|CodeCompanion.ACPAdapter }
---@return boolean
enabled = function(opts)
if opts.adapter and opts.adapter.opts then
return opts.adapter.opts.vision == true
end
return false
end,
opts = {
dirs = {}, -- Directories to search for images
filetypes = { "png", "jpg", "jpeg", "gif", "webp" }, -- Filetypes to search for
provider = providers.images, -- telescope|snacks|default
},
},
["mcp"] = {
path = "interactions.chat.slash_commands.builtin.mcp",
description = "Toggle MCP servers",
opts = {
contains_code = false,
provider = "default", -- snacks|default
},
},
["now"] = {
path = "interactions.chat.slash_commands.builtin.now",
description = "Insert the current date and time",
opts = {
contains_code = false,
},
},
["resume"] = {
path = "interactions.chat.slash_commands.builtin.resume",
description = "Resume a previous ACP session",
---@param opts { adapter: CodeCompanion.HTTPAdapter|CodeCompanion.ACPAdapter }
---@return boolean
enabled = function(opts)
if opts.adapter and opts.adapter.type == "acp" then
return true
end
return false
end,
opts = {
contains_code = false,
max_sessions = 500,
},
},
["rules"] = {
path = "interactions.shared.slash_commands.rules",
description = "Insert rules",
opts = {
contains_code = true,
interactions = { "chat", "cli" },
},
},
["symbols"] = {
path = "interactions.chat.slash_commands.builtin.symbols",
description = "Insert symbols for a selected file",
opts = {
contains_code = true,
provider = providers.pickers, -- telescope|fzf_lua|mini_pick|snacks|default
},
},
opts = {
acp = {
enabled = true, -- Enable ACP command completion
},
},
},
keymaps = {
options = {
modes = { n = "?" },
callback = "keymaps.options",
description = "Options",
hide = true,
},
completion = {
modes = { i = "<C-_>" },
index = 1,
callback = "keymaps.completion",
description = "[Chat] Completion menu",
},
send = {
modes = {
n = { "<CR>", "<C-s>" },
i = "<C-s>",
},
index = 2,
callback = "keymaps.send",
description = "[Request] Send response",
},
regenerate = {
modes = { n = "gr" },
index = 3,
callback = "keymaps.regenerate",
description = "[Request] Regenerate",
},
close = {
modes = {
n = "<C-c>",
i = "<C-c>",
},
index = 4,
callback = "keymaps.close",
description = "[Chat] Close",
},
stop = {
modes = { n = "q" },
index = 5,
callback = "keymaps.stop",
description = "[Request] Stop",
},
clear = {
modes = { n = "gx" },
index = 6,
callback = "keymaps.clear",
description = "[Chat] Clear",
},
codeblock = {
modes = { n = "gc" },
index = 7,
callback = "keymaps.codeblock",
description = "[Chat] Insert codeblock",
},
yank_code = {
modes = { n = "gy" },
index = 8,
callback = "keymaps.yank_code",
description = "[Chat] Yank code",
},
buffer_sync_all = {
modes = { n = "gba" },
index = 9,
callback = "keymaps.buffer_sync_all",
description = "[Chat] Toggle buffer syncing",
},
buffer_sync_diff = {
modes = { n = "gbd" },
index = 10,
callback = "keymaps.buffer_sync_diff",
description = "[Chat] Toggle buffer diff syncing",
},
next_chat = {
modes = { n = "}" },
index = 11,
callback = "keymaps.next_chat",
description = "[Nav] Next chat",
},
previous_chat = {
modes = { n = "{" },
index = 12,
callback = "keymaps.previous_chat",
description = "[Nav] Previous chat",
},
next_header = {
modes = { n = "]]" },
index = 13,
callback = "keymaps.next_header",
description = "[Nav] Next header",
},
previous_header = {
modes = { n = "[[" },
index = 14,
callback = "keymaps.previous_header",
description = "[Nav] Previous header",
},
change_adapter = {
modes = { n = "ga" },
index = 15,
callback = "keymaps.change_adapter",
description = "[Adapter] Change adapter and model",
},
fold_code = {
modes = { n = "gf" },
index = 15,
callback = "keymaps.fold_code",
description = "[Chat] Fold code",
},
debug = {
modes = { n = "gd" },
index = 16,
callback = "keymaps.debug",
description = "[Chat] View debug info",
},
system_prompt = {
modes = { n = "gs" },
index = 17,
callback = "keymaps.toggle_system_prompt",
description = "[Chat] Toggle system prompt",
},
rules = {
modes = { n = "gM" },
index = 18,
callback = "keymaps.clear_rules",
description = "[Chat] Clear Rules",
},
clear_approvals = {
modes = { n = "gtx" },
index = 19,
callback = "keymaps.clear_approvals",
description = "[Tools] Clear approvals",
},
yolo_mode = {
modes = { n = "gty" },
index = 20,
callback = "keymaps.yolo_mode",
description = "[Tools] Toggle YOLO mode",
},
goto_file_under_cursor = {
modes = { n = "gR" },
index = 21,
callback = "keymaps.goto_file_under_cursor",
description = "[Chat] Open file under cursor",
},
copilot_stats = {
modes = { n = "gS" },
index = 22,
callback = "keymaps.copilot_stats",
description = "[Adapter] Copilot statistics",
},
},
opts = {
compaction = {
trigger = 0.75, -- Compaction starts at 75% of the context window limit
enabled = function(adapter)
if adapter.type ~= "http" then
return false
end
-- Anthropic and OpenAI have their own server-side compaction
if adapter.vendor and (adapter.vendor == "anthropic" or adapter.vendor == "openai") then
return false
end
return true
end,
},
blank_prompt = "", -- The prompt to use when the user doesn't provide a prompt
completion_provider = providers.completion, -- blink|cmp|coc|default
debounce = 150, -- Time to debounce user input (milliseconds)
register = "+", -- The register to use for yanking code
wait_timeout = 2e6, -- Time to wait for user response before timing out (milliseconds)
yank_jump_delay_ms = 400, -- Delay before jumping back from the yanked code (milliseconds )
---@type string|fun(path: string)
goto_file_action = ui_utils.tabnew_reuse,
---This is the default prompt which is sent with every request in the chat
---interaction. It is primarily based on the GitHub Copilot Chat's prompt
---but with some modifications. You can choose to remove this via
---your own config but note that LLM results may not be as good
---@param ctx CodeCompanion.SystemPrompt.Context
---@return string
system_prompt = function(ctx)
return ctx.default_system_prompt
.. fmt(
[[Additional context:
All non-code text responses must be written in the %s language.
The user's current working directory is %s.
The current date is %s.
The user's Neovim version is %s.
The user is working on a %s machine. Please respond with system specific commands if applicable.
]],
ctx.language,
ctx.cwd,
ctx.date,
ctx.nvim_version,
ctx.os
)
end,
},
},
-- INLINE INTERACTION -----------------------------------------------------
inline = {
adapter = "copilot",
keymaps = {
stop = {
callback = "keymaps.stop",
description = "Stop request",
index = 4,
modes = { n = "q" },
},
},
editor_context = {
["buffer"] = {
path = "interactions.inline.editor_context.buffer",
description = "Share the current buffer with the LLM",
opts = {
contains_code = true,
},
},
["chat"] = {
path = "interactions.inline.editor_context.chat",
description = "Share the currently open chat buffer with the LLM",
opts = {
contains_code = true,
},
},
["clipboard"] = {
path = "interactions.inline.editor_context.clipboard",
description = "Share the contents of the clipboard with the LLM",
opts = {
contains_code = true,
},
},
},
},
-- CMD INTERACTION --------------------------------------------------------
cmd = {
adapter = "copilot",
opts = {
system_prompt = [[You are currently plugged in to the Neovim text editor on a user's machine. Your core task is to generate an command-line inputs that the user can run within Neovim. Below are some rules to adhere to:
- Return plain text only
- Do not wrap your response in a markdown block or backticks
- Do not use any line breaks or newlines in you response
- Do not provide any explanations
- Generate an command that is valid and can be run in Neovim
- Ensure the command is relevant to the user's request]],
},
},
-- CLI INTERACTION ---------------------------------------------------------
cli = {
agents = {},
opts = {
auto_insert = false, -- Enter insert mode when focusing the CLI terminal
},
providers = {
terminal = {
path = "interactions.cli.providers.terminal",
description = "Terminal CLI provider",
},
},
keymaps = {
next_chat = {
modes = { n = "}" },
callback = "keymaps.next_chat",
description = "[Nav] Next interaction",
},
previous_chat = {
modes = { n = "{" },
callback = "keymaps.previous_chat",
description = "[Nav] Previous interaction",
},
},
},
shared = {
editor_context = {
opts = {
excluded = {
buftypes = {
"nofile",
"quickfix",
"prompt",
"popup",
},
fts = {
"codecompanion",
"help",
"terminal",
},
},
},
["buffer"] = {
path = "interactions.shared.editor_context.buffer",
description = "Share the current buffer with the LLM",
opts = {
contains_code = true,
default_params = "diff", -- all|diff
has_params = true,
},
},
["buffers"] = {
path = "interactions.shared.editor_context.buffers",
description = "Share all open buffers with the LLM",
opts = {
contains_code = true,
default_params = "diff", -- all|diff
has_params = true,
},
},
["diagnostics"] = {
path = "interactions.shared.editor_context.diagnostics",
description = "Share diagnostics and code for the current buffer",
opts = {
contains_code = true,
},
},
["diff"] = {
path = "interactions.shared.editor_context.diff",
description = "Share the current git diff with the LLM",
opts = {
contains_code = true,
},
},
["messages"] = {
path = "interactions.shared.editor_context.messages",
description = "Share Neovim's message history with the LLM",
},
["quickfix"] = {
path = "interactions.shared.editor_context.quickfix",
description = "Share the quickfix list with the LLM",
opts = {
contains_code = true,
},
},
["selection"] = {
path = "interactions.shared.editor_context.selection",
description = "Share the current visual selection with the LLM",
opts = {
contains_code = true,
},
},
["terminal"] = {
path = "interactions.shared.editor_context.terminal",
description = "Share the latest terminal output with the LLM",
},
["viewport"] = {
path = "interactions.shared.editor_context.viewport",
description = "Share the code that you see in Neovim with the LLM",
opts = {
contains_code = true,
},
},
["this"] = {
path = "interactions.shared.editor_context.this",
description = "Smart context: visual selection if present, otherwise the current buffer (CLI only)",
opts = {
contains_code = true,
interactions = { "cli" },
},
},
},
keymaps = {
view_diff = {
description = "View the proposed diff",
modes = { n = "gv" },
opts = { nowait = true },
},
always_accept = {
callback = "keymaps.always_accept",
description = "Always accept changes in this buffer",
index = 1,
modes = { n = "g1" },
opts = { nowait = true },
},
accept_change = {
callback = "keymaps.accept_change",
description = "Accept change",
index = 2,
modes = { n = "g2" },
opts = { nowait = true, noremap = true },
},
reject_change = {
callback = "keymaps.reject_change",
description = "Reject change",
index = 3,
modes = { n = "g3" },
opts = { nowait = true, noremap = true },
},
cancel = {
description = "Cancel all pending tool calls",
modes = { n = "g4" },
opts = { nowait = true },
},
next_hunk = {
callback = "keymaps.next_hunk",
description = "Go to next hunk",
modes = { n = "}" },
},
previous_hunk = {
callback = "keymaps.previous_hunk",
description = "Go to previous hunk",
modes = { n = "{" },
},
},
},
},
-- MCP SERVERS ----------------------------------------------------------------
mcp = {
servers = {},
opts = {
default_servers = {}, -- List of server names to auto-start and add to chat
acp_enabled = true, -- Enable MCP servers with ACP adapters?
timeout = 30e3, -- Timeout for MCP server responses (milliseconds)
},
},
-- PROMPT LIBRARIES ---------------------------------------------------------
prompt_library = {
-- Users can define prompt library items in markdown
markdown = {
dirs = {},
},
},
-- RULES -------------------------------------------------------------------
rules = {
default = {
description = "Collection of common files for all projects",
files = {
".clinerules",
".cursorrules",
".goosehints",
".rules",
".windsurfrules",
".github/copilot-instructions.md",
"AGENT.md",
"AGENTS.md",
{ path = "CLAUDE.md", parser = "claude" },
{ path = "CLAUDE.local.md", parser = "claude" },
{ path = "~/.claude/CLAUDE.md", parser = "claude" },
},
is_preset = true,
},
CodeCompanion = {
description = "CodeCompanion rules",
parser = "claude",
---@return boolean
enabled = function()
-- Don't show this to users who aren't working on CodeCompanion itself
return vim.fn.getcwd():find("codecompanion", 1, true) ~= nil
end,
files = {
["adapters"] = {
description = "The adapters implementation",
files = {
".codecompanion/adapters/adapters.md",
},
},
["chat"] = {
description = "The chat buffer",
files = {
".codecompanion/chat.md",
},
},
["acp"] = {
description = "The ACP implementation",
files = {
".codecompanion/acp/acp.md",
},
},