Skip to content

为 MiniCode 引入模型感知的自动上下文压缩与 TUI 上下文占用指示 / Add model-aware auto-compaction and TUI context usage indicator to MiniCode #1

@LiuMengxuan04

Description

@LiuMengxuan04

背景 / Background

当前 main 分支的 MiniCode 还没有自动上下文压缩能力,也没有在 TUI 中显示当前上下文占用情况。

MiniCode on the current main branch does not yet have automatic context compaction, and it does not expose current context usage in the TUI.

Claude Code 在这方面的设计方向更完整:它会结合模型上下文窗口、当前 token 使用情况和自动压缩阈值,在会话接近上下文上限时主动处理,并把相关状态直接呈现在 UI 中。

Claude Code follows a more complete design direction here: it combines model context limits, current token usage, and auto-compaction thresholds, proactively handles long sessions before they hit the blocking limit, and surfaces this state directly in the UI.

这个 issue 用来跟踪把这条方向引入 MiniCode。

This issue tracks bringing the same direction into MiniCode.

目标 / Goal

为 MiniCode 增加一套更完整的上下文管理能力,包括:

  • 自动上下文压缩
  • 模型感知的上下文窗口与压缩阈值
  • 基于供应商 usage 数据的完整 token 记账链路
  • TUI 中的上下文占用和压缩状态显示

Add a more complete context-management system to MiniCode, including:

  • automatic context compaction
  • model-aware context window and compaction thresholds
  • a complete token accounting pipeline based on provider usage data
  • TUI display for context usage and compaction status

修改方向 / Direction

1. 引入自动上下文压缩 / Introduce automatic context compaction

在长会话中自动压缩较早历史,保留最近一段原始消息继续执行。

Automatically compact earlier history during long sessions while preserving a recent raw-message tail for continuation.

2. 阈值改为模型感知 / Make thresholds model-aware

压缩阈值不应使用固定常量,而应基于模型的上下文窗口、输出保留预算和实际 headroom 计算。

Compaction thresholds should not rely on a fixed constant. They should be derived from the model context window, reserved output budget, and actual headroom.

3. 接入 usage 驱动的 token 记账 / Add usage-driven token accounting

不要只依赖本地估算。需要把模型供应商返回的 usage 数据纳入主流程,用于:

  • 记录输入和输出 token 使用量
  • 跟踪会话中的上下文占用演进
  • 为自动压缩和 UI 状态提供更可靠的依据

Do not rely only on local estimation. Provider-reported usage should be integrated into the main flow to:

  • record input and output token usage
  • track context growth across the session
  • provide a more reliable basis for auto-compaction and UI state

4. 在 TUI 中显示上下文状态 / Show context state in the TUI

在 TUI 中展示当前上下文占用、剩余 headroom,以及距离自动压缩或阻塞上限还有多远。

Expose current context usage, remaining headroom, and distance to auto-compaction or blocking limits directly in the TUI.

验收标准 / Acceptance Criteria

  • main 分支新增自动上下文压缩能力

  • 自动压缩阈值与模型上下文窗口相关

  • MiniCode 能接入并使用供应商返回的 usage 数据

  • TUI 能显示当前上下文占用和压缩相关状态

  • 长会话可以在压缩后继续执行

  • 不破坏现有交互流程

  • npm run check 通过

  • Automatic context compaction is added to main

  • Compaction thresholds are tied to model context size

  • MiniCode integrates and uses provider-reported usage data

  • The TUI displays current context usage and compaction-related state

  • Long sessions can continue after compaction

  • Existing interaction flows are not broken

  • npm run check passes

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions