AI-assisted engineering/AI-collaboration build

Fix the SMS segment splitter for order updates

AI-collaboration buildHard40 min

Order updates go out as text messages, and the carrier bills each segment. Since the splitter was rewritten, some messages break in the wrong places and some cost more than they should.

Your task

Fix segments so it honors its contract. The assistant may help, and it may be wrong more than once.

  • a message is GSM-7 when every character is in GSM_BASIC or GSM_EXTENDED; any other character makes the whole message UCS-2
  • in GSM-7 an extended character takes 2 units; in UCS-2 a character takes as many units as it has UTF-16 code units, so most emoji take 2
  • a message of up to 160 GSM-7 or 70 UCS-2 units goes whole; a longer one splits into parts of at most 153 or 67 units
  • a character that does not fit in what is left of a part starts the next one
  • leave run_case alone; it is what the tests call

Hidden tests run at submit. Your prompts, runs and edits are the trace the critique reads.