Loading...
Loading...
Compare original and translation side by side
from scripts.compactor import ContextCompactor
compactor = ContextCompactor()
if compactor.should_compact(context, limit=100000):
compacted = compactor.compact(context)from scripts.compactor import ContextCompactor
compactor = ContextCompactor()
if compactor.should_compact(context, limit=100000):
compacted = compactor.compact(context)compacted = compactor.compact(context)compacted = compactor.compact(context)undefinedundefined┌─────────────────────────────────────────────────────────────┐
│ PRESERVATION PRIORITY │
├─────────────────────────────────────────────────────────────┤
│ │
│ MUST PRESERVE (Never remove) │
│ ├─ Architectural decisions │
│ ├─ Unresolved bugs and blockers │
│ ├─ Current feature state │
│ ├─ Recent file changes (last 5) │
│ └─ Error patterns and solutions │
│ │
│ CAN SUMMARIZE (Compress to summary) │
│ ├─ Completed features (list of IDs) │
│ ├─ Resolved errors (brief mention) │
│ └─ Historical decisions (key points) │
│ │
│ CAN DISCARD (Remove entirely) │
│ ├─ Redundant tool outputs │
│ ├─ Stale search results │
│ ├─ Superseded messages │
│ └─ Verbose logging │
│ │
└─────────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────────┐
│ 保留优先级 │
├─────────────────────────────────────────────────────────────┤
│ │
│ 必须保留(绝不删除) │
│ ├─ 架构决策 │
│ ├─ 未解决的bug和阻塞问题 │
│ ├─ 当前功能状态 │
│ ├─ 最近的文件变更(最近5次) │
│ └─ 错误模式与解决方案 │
│ │
│ 可摘要(压缩为摘要内容) │
│ ├─ 已完成功能(ID列表) │
│ ├─ 已解决错误(简要提及) │
│ └─ 历史决策(关键点) │
│ │
│ 可丢弃(完全移除) │
│ ├─ 冗余工具输出 │
│ ├─ 过期搜索结果 │
│ ├─ 已被替代的消息 │
│ └─ 冗余日志 │
│ │
└─────────────────────────────────────────────────────────────┘| Context Type | Limit | Action |
|---|---|---|
| < 50% | Normal | No action |
| 50-75% | Warning | Prepare for compaction |
| 75-90% | Compact | Trigger compaction |
| > 90% | Critical | Aggressive compaction |
| 上下文类型 | 限制比例 | 操作 |
|---|---|---|
| < 50% | 正常 | 不执行操作 |
| 50-75% | 警告 | 准备压缩 |
| 75-90% | 执行压缩 | 触发压缩 |
| > 90% | 紧急 | 强制压缩 |
references/COMPACTION-STRATEGY.mdreferences/TOKEN-BUDGETS.mdreferences/COMPACTION-STRATEGY.mdreferences/TOKEN-BUDGETS.mdscripts/compactor.pyscripts/importance_scorer.pyscripts/summarizer.pyscripts/token_estimator.pyscripts/compactor.pyscripts/importance_scorer.pyscripts/summarizer.pyscripts/token_estimator.py