modeOfSystemMessage returns the canonical mode name carried by the system message, or "" when the message either isn't a system role or carries no marker. Used by purgeStaleModeSystems to decide whether each entry should survive a mode transition.
(m models.Message)
| 45 | // or carries no marker. Used by purgeStaleModeSystems to decide |
| 46 | // whether each entry should survive a mode transition. |
| 47 | func modeOfSystemMessage(m models.Message) string { |
| 48 | if m.Role != "system" { |
| 49 | return "" |
| 50 | } |
| 51 | if match := modeMarkerRe.FindStringSubmatch(m.Content); len(match) == 2 { |
| 52 | return match[1] |
| 53 | } |
| 54 | // SystemParts may carry the marker too when the flat Content is |
| 55 | // empty (Anthropic-style block emission). Walk the parts as a |
| 56 | // fallback so we don't miss a marker that lives only in the |
| 57 | // structured side of the message. |
| 58 | for _, p := range m.SystemParts { |
| 59 | if match := modeMarkerRe.FindStringSubmatch(p.Text); len(match) == 2 { |
| 60 | return match[1] |
| 61 | } |
| 62 | } |
| 63 | return "" |
| 64 | } |
| 65 | |
| 66 | // purgeStaleModeSystems removes every system message whose mode |
| 67 | // marker does NOT match `currentMode`. Messages without a marker |
no outgoing calls