When tools have no parameters, llm_tool_param_fields_to_json_schema
returns an empty Lua table {}. vim.json.encode serializes empty tables
as JSON arrays [] instead of objects {}, causing Anthropic API to reject
requests with "tools.N.custom.input_schema.properties: Input should be
a valid dictionary" error.
Solution: Use vim.empty_dict() for empty properties to ensure correct
JSON object {} serialization instead of array [].
Tested with Claude Sonnet 4.5 - tools now work correctly without
schema validation errors.
Separate managing of a sign (">") placement for the input buffer and
defining a highlight for prompt logger and move the latter into
PromptLogger.init().
Between Utils.prepend_line_number() and its only caller, there is a lot
of conversions from list to string to list and back to string. Simplify
all of this by making it accept and return a list of strings, which
avoids unnecessary splitting and joining.
The implementation was updated to use vim.iter():map() and
string.format() for better performance and to align with the idiomatic
functional style used elsewhere in the project.
The name of the function has also been tweaked and is now
"prepend_line_numbers()" to better reflect that it operates on a list of
strings.
The caller has been updated to match the new function signature.
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.
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.
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.
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.