Bug 1 (400 API error): applyCompressionBlocks could remove toolResult
messages while leaving their paired assistant(tool_use) message intact.
This produced invalid API sequences that Claude rejected with:
messages.N: tool_use ids found without tool_result blocks immediately after
The fix adds two boundary expansions before the splice:
- Expand lo backward: if messages[lo-1] is an assistant whose toolCall
ids appear as toolResult.toolCallId values inside [lo..hi], pull the
assistant into the range
- Expand hi forward: for assistants inside [lo..hi], extend hi to include
any consecutive toolResult messages that immediately follow hi
This ensures tool_use/tool_result pairs are always removed together.
Bug 2 (autocomplete crash): harden getArgumentCompletions to return an
explicitly typed AutocompleteItem[] | null, filter on value (not label,
matching pi-tui's internal contract), and add a typeof guard ensuring no
item with a non-string value can reach getBestAutocompleteMatchIndex.