resolveCompactionHostWiring function

CompactionHostWiring resolveCompactionHostWiring({
  1. required Model mainModel,
  2. Model? smolModel,
  3. int? contextWindowCap,
  4. CompactionSettings? settingsOverride,
  5. int systemOverheadTokens = 0,
  6. bool enabled = compactionEnabledByDefault,
})

Resolves one host's compaction wiring from its inputs — the shared semantics both hosts compute through:

  • window = effectiveContextWindow (owner cap clamps down / raises to the served truth, issues #273/#729);
  • conversationWindow = the effective window minus the host's fixed request overhead (CLI: 0; app: the measured system-prompt / tool instruction tokens);
  • settings = the explicit override when the host plumbed one, else CompactionSettings.forWindow of the conversation window;
  • smolModel = the resolved smol role, kept only when distinct from the main model;
  • retry/enabled = the shared defaults (compactionEnabledByDefault, the pinned summarizer ladder).

Implementation

CompactionHostWiring resolveCompactionHostWiring({
  required Model mainModel,
  Model? smolModel,
  int? contextWindowCap,
  CompactionSettings? settingsOverride,
  int systemOverheadTokens = 0,
  bool enabled = compactionEnabledByDefault,
}) {
  final window = effectiveContextWindow(
    mainModel.contextWindow,
    contextWindowCap,
  );
  final conversation = window - systemOverheadTokens;
  final distinct =
      smolModel != null &&
      (smolModel.provider != mainModel.provider ||
          smolModel.id != mainModel.id);
  return CompactionHostWiring(
    window: window,
    conversationWindow: conversation > 0 ? conversation : 0,
    settings:
        settingsOverride ??
        CompactionSettings.forWindow(conversation > 0 ? conversation : 0),
    smolModel: distinct ? smolModel : null,
    enabled: enabled,
  );
}