HarveyAI document workflows need to identify every occurrence of configured keyword phrases so the UI can annotate them. Given a text string and a list of non-empty keyword phrases, return all matches, including overlapping and nested matches.
Use zero-based, half-open character spans. For each match, return a dictionary with keyword, start, and end, where text[start:end] equals the keyword. Matching is case-sensitive and uses exact characters, including spaces and punctuation. Return results sorted by start, then end, then keyword.
Implement annotate_keywords(text, keywords). The input is a string text and a list of distinct non-empty strings keywords. Return a list of annotation dictionaries. Every occurrence of every keyword must appear exactly once in the output.
def annotate_keywords(text, keywords):