@bastani/atomic 0.8.31-alpha.2 → 0.8.31-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ import { ATOMIC_GUIDE_COMMAND_NAME, ATOMIC_GUIDE_HELP_CHOICES, atomicGuideModeFo
23
23
  import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage, formatUnresolvedModelMessage, } from "./auth-guidance.js";
24
24
  import { executeBashWithOperations } from "./bash-executor.js";
25
25
  import { calculateContextTokens, collectEntriesForBranchSummary, contextCompact as runContextCompact, estimateContextTokens, generateBranchSummary, prepareContextCompaction, shouldCompact, validateContextDeletionRequest, } from "./compaction/index.js";
26
- import { getModelDefaultContextWindow, getSupportedContextWindows, selectContextWindow } from "./context-window.js";
26
+ import { getEffectiveInputBudget, getModelDefaultContextWindow, getSupportedContextWindows, selectContextWindow } from "./context-window.js";
27
27
  import { formatCopilotProviderError, parseCopilotPromptLimitError } from "./copilot-errors.js";
28
28
  import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
29
29
  import { exportSessionToHtml } from "./export-html/index.js";
@@ -2009,7 +2009,11 @@ export class AgentSession {
2009
2009
  else {
2010
2010
  contextTokens = calculateContextTokens(assistantMessage.usage);
2011
2011
  }
2012
- if (shouldCompact(contextTokens, contextWindow, settings)) {
2012
+ // Compact against the effective input budget (the hard prompt cap for providers like Copilot
2013
+ // that advertise a larger total window) so we compact before overrunning the server-side limit
2014
+ // rather than relying on reactive overflow recovery near the cap.
2015
+ const compactionBudget = this.model ? getEffectiveInputBudget(this.model) : contextWindow;
2016
+ if (shouldCompact(contextTokens, compactionBudget, settings)) {
2013
2017
  await this._runAutoCompaction("threshold", false);
2014
2018
  }
2015
2019
  }
@@ -2017,7 +2021,11 @@ export class AgentSession {
2017
2021
  if (!this.model || this.model.provider !== "github-copilot" || !assistantMessage.errorMessage)
2018
2022
  return false;
2019
2023
  const promptLimitError = parseCopilotPromptLimitError(assistantMessage.errorMessage);
2020
- return promptLimitError !== undefined && this.model.contextWindow > promptLimitError.limitTokens;
2024
+ // Compare against the effective input budget (the model's real prompt cap), not the displayed
2025
+ // total window. A rejection at the prompt cap is a normal overflow we should compact-and-retry;
2026
+ // only a rejection *below* the cap (e.g. a missing long-context entitlement dropping the account
2027
+ // to a lower server tier) keeps the friendly error visible instead of silently compacting down.
2028
+ return promptLimitError !== undefined && getEffectiveInputBudget(this.model) > promptLimitError.limitTokens;
2021
2029
  }
2022
2030
  /**
2023
2031
  * Internal: remove the trailing overflow error from retry context if it is still present.