shouldSpillUserMessage function

bool shouldSpillUserMessage(
  1. String text,
  2. SpillsConfig config,
  3. int budgetTokens
)

True when a user message's TEXT spills (issue #1760): the message alone threatens the live window budget — its token estimate exceeds SpillsConfig.userFraction of budgetTokens (the effective context window minus the compaction reserve) — AND the text is past the absolute SpillsConfig.userThreshold byte floor. Pure function.

Implementation

bool shouldSpillUserMessage(
  String text,
  SpillsConfig config,
  int budgetTokens,
) {
  if (!config.enabled) {
    return false; // the section kill-switch covers both paths
  }
  if (config.userThreshold <= 0) return false; // the user path's own switch
  if (text.trim().isEmpty) return false;
  if (utf8.encode(text).length <= config.userThreshold) return false;
  return estimateStringTokens(text) >
      (config.userFraction * budgetTokens).floor();
}