Skip to content

feat: dynamic context pressure warning with model-aware thresholds#20

Merged
tuanhung303 merged 1 commit intomasterfrom
feat/dynamic-context-pressure
Feb 8, 2026
Merged

feat: dynamic context pressure warning with model-aware thresholds#20
tuanhung303 merged 1 commit intomasterfrom
feat/dynamic-context-pressure

Conversation

@tuanhung303
Copy link
Owner

Summary

  • Add dynamic context pressure warning based on 70% of the agent's actual context window
  • Show 🟢/🟡/🟠/🔴 {percent}% in status bar with | separator
  • Reasoning block notifications show 🧠 (xN) instead of 🧠 "—"
  • Periodic checkpoint reminder shows model info, remaining tokens, and savings from pruning

Changes

Core

  • lib/strategies/utils.tsMODEL_CONTEXT_WINDOWS map (Claude 200K, GPT 128K, Gemini 1M, DeepSeek 128K), resolveModelContextWindow(), getEffectiveContextThreshold(), getContextStatus()
  • lib/state/types.tsContextPressure interface on SessionState (transient, recomputed each turn)
  • lib/hooks.ts — Compute context pressure after syncSessionState, populate state.contextPressure

Config

  • lib/config/schema.ts — Replace maxContextTokens with fallbackContextWindow (200K) + warningThresholdPercent (0.7)
  • lib/config/defaults.ts — Updated defaults

UI

  • lib/ui/utils.tsformatStatsHeader() accepts SessionState, appends status emoji + percent, uses | separator
  • lib/ui/notification.ts — Pass state to formatStatsHeader()
  • lib/ui/minimal-notifications.ts — Reasoning blocks show 🧠 (xN) not 🧠 "—"
  • lib/ui/pruning-status.ts — Same reasoning fix in formatItemizedDetails()
  • lib/messages/todo-reminder.ts — Rich checkpoint: model info, status label, remaining tokens, savings

Tests

  • Updated 8 test files with new contextPressure state and config fields
  • All 557 tests pass

Example Output

Status bar:

「 💬 12(6K) ▼ | 🧠 141(282K) ▼ | ⚙️ 177(143.8K) ▼ | 🟡 59% 」- 🧠 (x4)

Checkpoint reminder:

⚡ Context: 59% 🟡 Elevated — 82.0K tokens remaining
📋 118.0K / 200.0K (200.0K context window)
🤖 Model: Claude Opus (200.0K context)
💾 Savings: 12.3K tokens reclaimed via pruning

- Add MODEL_CONTEXT_WINDOWS map with known model context sizes (Claude, GPT, Gemini, DeepSeek)
- Compute context pressure per turn: rawWindow × 70% threshold, status labels (🟢🟡🟠🔴)
- Add contextPressure to SessionState (transient, recomputed each turn)
- Status bar: replace ₊ with | separator, show status emoji + percent (e.g. 🟡 59%)
- Reasoning notifications: show 🧠 (xN) instead of 🧠 "—" for thinking blocks
- Reminder checkpoint: show model info, remaining tokens, savings from pruning
- Replace static maxContextTokens with fallbackContextWindow + warningThresholdPercent
- Remove outputBufferPercent — use raw context window directly
@tuanhung303 tuanhung303 merged commit 5bfd191 into master Feb 8, 2026
3 checks passed
@tuanhung303 tuanhung303 deleted the feat/dynamic-context-pressure branch February 9, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant