regex-partial: fix partial matching with alternations
Fix partial regex matching when one alternative can match empty and
"steals" the match from other alternatives.
The issue occurred with the Hermes 2 Pro tool call regex which has
multiple alternatives. The first alternative could match empty (due
to optional groups), causing the combined reversed partial pattern
to return an empty match. This prevented detection of partial matches
like `<tool_call>` or `<function=name` during streaming.
The fix:
- Add split_top_level_alternations() to split patterns by top-level |
- Store each alternative's reversed partial regex separately
- Try alternatives individually when combined pattern returns empty
This ensures incomplete tool call markers at the end of streaming
output are held back from being emitted as content (e.g., to TTS).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>