1570 Commits

Author SHA1 Message Date
Dmitry Torokhov
c6d2783975 fix(sidebar): account for sidebar header on/off for selected code
Current implementation always says that first 5 lines of code is shown
when selected code does not fully fit into its window. This is not
correct as the window can be resized, may have a header occupying one
line, and the lines may not be the first ones. Also the wording is
awkward.

Correct these issues by checking current window height, accounting for
the potential header presence by checking sidebar.enabled config flag,
and updating the message format to be more concise:

" Selected Code (4/15 lines)"

While at it switch to using Utils.count_lines() which does not need
creating temporary tables.

Note that this does not deal with the header info being stale after
resizing sidebar windows.
2025-07-22 17:49:56 +08:00
Dmitry Torokhov
aa606b6147 refactor(history): change HistoryMessage:new() to accept role and item
Change the constructor to accept role and a single content item instead
of raw AvanteLLMMessage instance. This will help when we will start
changing message.content from being a string or a list of tables to just
a string or a single table.
2025-07-22 17:49:28 +08:00
Dmitry Torokhov
2d9f8fd252 refactor(sidebar): use helpers when working with history
Do not poke directly into avante.HistoryMessage instances, use
appropriate helpers instead.
2025-07-22 17:49:28 +08:00
Dmitry Torokhov
86e8563125 refactor(llm_tools): use History.Helpers.get_tool_result_data()
Avoid poking into internals of avante.HistoryMessage, and use
appropriate helper instead.
2025-07-22 17:49:28 +08:00
Dmitry Torokhov
394e4d79eb refactor(message): add helper to update contents of simple text message
Add update_content() helper so code outside of history module does not
need to know details of the message structure.
2025-07-22 17:49:28 +08:00
Dmitry Torokhov
e82b159f65 refactor(history): add a helper to fetch text from messages and use it
This adds History.Helpers.get_text_data() helper to fetch contents of a
"text" message. This removes the need to know internals of message
structure outside of history module.
2025-07-22 17:49:28 +08:00
Dmitry Torokhov
663433a5ed refactor(message): use vim.tbl_extend() in Message:new() to apply options
It is unwieldy to handle fields in opt table one by one. Luckily there
is vim.bl_extend("force", ...) that can help us here.

Also move annotation for opts from parameter to a separate class to make
it easier to work with.
2025-07-22 17:49:28 +08:00
bhaktatejas922
07457293d4 fix(docs): morph website 2025-07-22 17:45:58 +08:00
yetone
db56901594 fix: result winid is nil (#2508) 2025-07-22 17:45:14 +08:00
ras0q
7ed3a0e761 doc: the build opt must return a string value
The `build` opt must be fun(LazyPlugin) or string or false or a list of
build commands, not fun():string

Ref: https://lazy.folke.io/spec
2025-07-21 12:10:40 -07:00
yetone
e9c031ab6b chores: morph model (#2501) 2025-07-22 00:02:34 +08:00
yetone
27a88c095f fix: incorrect diff (#2500) 2025-07-21 23:59:12 +08:00
Daniel Nyong
c694772d68 fix: vertex gemini 2025-07-21 21:55:53 +08:00
doodleEsc
3fcfa6ec05 refactor: refactor TODO handling to context messages
- Refactor TODOs handling: move logic to `context_messages` instead of using `template_opts`
- Improve todo message filtering by using more precise tags (`<todos>...</todos>`)
- Append TODOs after history messages
- Remove the TODOs section from `_task-guidelines.avanterules` template

Signed-off-by: doodleEsc <cinuor@gmail.com>
2025-07-21 16:56:03 +08:00
Dmitry Torokhov
0fe0f219e4 fix(sidebar): correctly exit visual mode
Commit a9b01e7 ("chores: use stopinsert (#1745)") replaced uses of
vim.api.nvim_feedkeys(...) with proper commands to exit and enter insert
mode. However "stopinsert" does not help when editor is in visual mode.

Unfortunately there is no dedicated command to exit visual mode so we
have to go back to simulating keystrokes again.
2025-07-21 16:49:08 +08:00
yetone
e730260796 feat: handle simple request 2025-07-21 13:34:48 +08:00
Dmitry Torokhov
beeea5cb1c refactor(sidebar): get rid of winids table, use containers table
Now that we have a table listing all containers and can iterate over it
we no longer need a separate table with window IDs that we need to
maintain. Remove it.
2025-07-21 13:31:07 +08:00
Dmitry Torokhov
7d60b51324 refactor(sidebar): move sub-windows into a table
Maintaining secondary table of window IDs is cumbersome and is prone to
getting out of sync with the true state of the sidebar. In preparation
for removal of winids table move all containers (sub-windows of the
sidebar) into "containers" table.

The change is mostly mechanical rename with following exceptions:

 - Sidebar:reifresh_winids() and other places where the code scanned
   entire Sidebar object looking for tables with specific fields, such
   as "winid", or "mount" needed to be adjusted for the new structure

 - Sidebar:new() and Sidebar:reset() have been adjusted to make better
   use of the new sub-table.
2025-07-21 13:31:07 +08:00
Dmitry Torokhov
714084d2f5 refactor(sidebar): remove Sidebar:is_focused()
The method is not used anywhere, remove it.
2025-07-21 13:31:07 +08:00
yetone
2d0b6875dd chores: refine top-level-symbols prompts 2025-07-21 13:22:40 +08:00
yetone
75ebef9fbe fix: tool_info is nil 2025-07-21 11:50:55 +08:00
yetone
0490927061 fix: edit_file is an edit tool 2025-07-21 11:14:19 +08:00
Dmitry Torokhov
9ccf721435 refactor(sidebar): avoid temporary table in Sidebar:update_content()
Under the hood vim.list_extend() does the same loop over the source
table and uses table.insert() to append the values to the destination
table, so using a temporary table makes little sense.

Switch to directly inserting (appending) values into history_lines
table.
2025-07-19 13:58:11 +08:00
yetone
0618dbc151 chore: update README with Fast Apply instructions 2025-07-19 13:57:17 +08:00
Dmitry Torokhov
2335ea3d15 refactor(history): reduce computational complexity when handling history
When updating chat history to be used in LLM request there are several
instances where we do O(n^2) operations: scanning all messages to locate
a tool "use" and for each use scan messages again to locate
corresponding "result".

Refactor the code to scan messages once collecting tool uses and results
together, and then do 2nd scan to drop incomplete tool invocations and
refresh "view" and "edit" results with the latest content.

Also reduce number of pre-scan loops (where we discard partially
generated messages or messages that are not interesting or too-old) by
combining them when possible.

This reduces time to scan initial 417 messages on my system (which
result in 576 final messages) from 0.32 to 0.12 seconds.
2025-07-18 22:36:21 -07:00
Dmitry Torokhov
c2e4ae5ef6 fix(llm): fix rate limit handling
Rate limit handling seems to be broken: it starts an one-shot timer
with callback that reschedules the timer each second and prints/updates
messages. Simultaneously it schedules a deferred by 1 second function
that cancels the timer and resumes the stream. This results in the timer
executing at most once, and stream resume happening way too early.

Fix this by switching to use repeating timer with first instance
executing immediately. All message handling is moved into the timer
callback. Once countdown is complete the same callback will stop and
destroy the timer and resume the stream.
2025-07-18 22:35:44 -07:00
yetone
b4c9246461 fix: find symbol definition ool 2025-07-17 20:37:57 +08:00
yetone
1dc195d9ef fix: edit_file cannot find old str 2025-07-17 19:49:08 +08:00
yetone
bf3c210584 fix: assistant message content must be a string 2025-07-17 17:05:52 +08:00
yetone
bc1de981d8 fix: on_complete is nil 2025-07-17 16:41:43 +08:00
yetone
a08a2e3579 feat: add original_content for history message 2025-07-17 15:45:23 +08:00
yetone
cd81fbf8af fix: tool_use_id is nil 2025-07-17 14:29:17 +08:00
yetone
cf5234b4d9 optimize: reduce copilot invocation consumption 2025-07-17 14:21:34 +08:00
yetone
5ea24f59fa fix: clear useless parameters 2025-07-17 13:50:33 +08:00
yetone
2a16e7d4d9 fix: do not modify the tool_use input 2025-07-16 20:18:24 +08:00
yetone
ae06698c30 feat: add moonshot provider 2025-07-16 19:04:46 +08:00
yetone
18ea95d965 fix: refine docs 2025-07-16 18:38:55 +08:00
yetone
adbd296ba6 feat: integrated morph 2025-07-16 18:34:52 +08:00
doodleEsc
1455ed6005 refactor(templates): Prioritize copying system templates to ensure latest version
- Refactor template copying order
2025-07-16 17:33:17 +08:00
Dmitry Torokhov
966eef743b refactor(history): move message rendering into history module
Move code related to converting history messages into UI representation
from utils into history/render.lua for better code organization and
clean up the implementation.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
06d9d8cec3 refactor(utils): remove history_messages_to_messages() function
Utils.history_messages_to_messages() is not used anywhere, remove it.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
d7c48075a5 refactor(history): move code collecting pending tools to history
Code dealing with scanning history messages and extracting some data or
state belongs to avante/history/ so move it there. Along with the move
update the implementation to make use of get_tool_use_data() and
get_tool_result_data() helpers to simplify it.

Also rename the function to History.get_pending_tools() to better
reflect its purpose: "uncalled" means something that was done without
request, unsolicited, not something that has not completed yet.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
b64120749f refactor(history): use get_tool_(result|use_data)() in dispatch_agent.lua
Using these helpers simplifies the code and provides better
encapsulation.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
36e116795d refactor(history): make use of get_tool_(use|result)_data() in llm.lua
Simplify the code locating viewed files as well as code locating last
completion attempt by using these new helpers.

Also avoid using "goto" in simple loops.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
47ad90b389 fix: when deleting tool use also delete tool result
Tool results are not useful without their "use" messages, so delete them
when deleting "use" ones.

Makes use of the new get_tool_use_data() and get_tool_result_data()
helpers.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
520ca47a8f refactor(history): add helpers to get content of tool "use" and "result"
There are many places in the code that wants to work with content of
"tool use" and "tool result" messages. Currently such code uses
is_tool_use_message() and is_tool_result() message to check if message
is of right kind, and then pokes into message internals. This is not
very efficient.

Introduce get_tool_use_data() and get_tool_result_data() that would
return contents of the message if it is of right kind, or nil otherwise.

Also introduce get_tool_result() that attempts to locate result of a
tool execution by its invocation ID.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
06cc3b3f21 refactor(history): add helpers to generate synthetic history messages
Add helpers such as HistoryMessage:new_assistant_synthetic() and
HistoryMessage:new_user_syntheric() to make callers more compact and
understandable.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
34907fc1cd refactor(history): start moving history-related code into avante/history
The utils module has grown too big and contains unrelated functionality.
Start moving code related to managing history messages comprising chat
history into lua/avante/history module to keep the code more manageable.
2025-07-16 12:49:15 +08:00
Dmitry Torokhov
85a9fcef95 fix(types): add is_user_declined field to AvanteLLMMessageContentItem
This field has been added to AvanteLLMToolResult, so it needs to be
included in AvanteLLMMessageContentItem as well.
2025-07-16 12:49:15 +08:00
yetone
127a12a878 fix: trim escapes for write_to_file tool (#2455) 2025-07-16 12:04:22 +08:00