← Back to Skills Marketplace
relunctance

Context Compressor

by Gao.QiLin · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ⚠ suspicious
106
Downloads
0
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install hawk-context
Description
Context Compressor — Real-time conversation context compression engine. Activates when user says "compress context", "压缩上下文", "上下文爆了", "context full", "上下文瘦身...
README (SKILL.md)

Context Compressor 🦅

纯上下文压缩引擎 — 不是记忆库,是救命工具。 当上下文爆炸前,压缩当前对话,继续轻松对话。


核心定位

工具 做什么 何时用
Context Compressor 压缩当前对话上下文 现在、立刻、当上下文快满
memory-lancedb-pro 跨会话持久记忆 对话之间存取知识
context-hawk 长期记忆管理 日常沉淀

Context Compressor = 急救工具。memory-lancedb-pro/context-hawk = 日常工具。


触发方式

自动触发(推荐):

  • 上下文超过 70% 时自动提示压缩
  • 每 10 轮对话自动检查水位

手动触发

  • "压缩上下文" / "compress context"
  • "上下文爆了" / "context full"
  • "瘦身" / "reduce context"
  • /compress

Quick Start

# Install skill
openclaw skills install ./context-compressor.skill

# Auto-link command to ~/bin (one-time)
bash ~/.openclaw/workspace/skills/context-compressor/scripts/install.sh
source ~/.bashrc

# Compress current conversation
hawk-compress --level normal --keep 5

# Dry run (preview)
hawk-compress --dry-run --level light --keep 3

# Python API
python3 -c "from hawk_compress import ContextCompressor; \
  c = ContextCompressor(keep_recent=5); \
  r = c.compress(your_chat_history); \
  print(r['stats']['ratio'])"

压缩原理

输入(压缩前)

[完整对话历史 — 180k tokens — 爆炸边缘]
System: 你是一个助手...
User: 第一个问题...
Assistant: 第一个回答...
User: 第二个问题...
Assistant: 第二个回答...
... (越来越长)

输出(压缩后)

{
  "compressed_prompt": "...[结构化压缩后的对话]...",
  "original_tokens": 180000,
  "compressed_tokens": 32000,
  "ratio": "5.6x",
  "kept_messages": 5,
  "summarized_count": 87,
  "compression_level": "normal",
  "timestamp": "2026-03-29T00:39:00+08:00"
}

压缩层级

层级 触发 效果 适用
light 60-70% 摘要 > 30天的消息 日常维护
normal 70-85% 摘要 + 保留最近10轮 推荐默认
heavy 85-95% 只保留最近5轮 + 核心摘要 紧急急救
emergency > 95% 只保留系统提示 + 最近3轮 立即执行

系统指令永久保留

以下内容永远不参与压缩(完整保留):

  • System Prompt / SOUL.md / AGENTS.md
  • 用户设定的角色定义
  • 核心规则和约束
  • 当前的任务描述

重要度过滤

压缩时自动判断每条消息的重要度:

重要度 消息类型 处理方式
🔴 极高 决策/规则/任务 保留原文
🟡 高 技术方案/代码片段 保留摘要
🟢 中 一般讨论 摘要或合并
⚪ 低 闲聊/确认/废话 直接丢弃

压缩策略

1. 消息摘要

把每条老消息压缩为一句话:

User: 讨论了Laravel的四层架构,讨论了Controller层的作用...
  → [摘要] User就Laravel四层架构提出问题

2. 合并重复

重复的说明/确认/指令合并为一条:

User: 好的
User: 好的
User: 明白了
  → [合并] User确认理解

3. 代码折叠

长代码片段只保留文件路径和关键行号:

[代码: app/Logic/OrderLogic.php — 45行] → [代码折叠]

4. 时间戳裁剪

同一时间段内的密集对话压缩为一条:

[上午10:00-10:30 共12轮对话] → [摘要]

压缩后的上下文格式

## 对话摘要

[最近5轮完整对话]
User: 最新问题...
Assistant: 最新回答...

[历史摘要]
- 2026-03-28: 讨论了Skill架构,决定不拆分
- 2026-03-28: 补充了DAO查询模式
- 2026-03-28: 完成qujin-laravel-team Skill v2

## 任务状态
- 当前任务:压缩上下文
- 进度:进行中

## 核心规则(永久保留)
[系统提示内容]

## 用户偏好(永久保留)
[关键偏好]

参考文档

文档 用途
references/compression-logic.md 压缩算法详解
references/auto-trigger.md 自动触发机制
references/structured-output.md JSON输出格式
references/cli.md CLI工具
Usage Guidance
Do not install this package yet. Specific issues to check before proceeding: - Missing executable: README and install.sh expect a scripts/hawk-compress file but the manifest does not include it. Ask the publisher for the missing executable or full source code. Installing the provided install.sh as-is will create a broken symlink. - Installer side-effects: the install script appends to your ~/.bashrc and creates ~/bin/hawk-compress. If you accept, be prepared to undo changes to ~/.bashrc and remove the symlink. Inspect the install.sh and run it manually in a controlled environment (or edit it) rather than running it automatically. - File writes: the tool claims it will write compression history to memory/today.md — confirm where that path is (skill workspace vs your home) and whether you are comfortable storing compressed conversation content on disk. - Auto-trigger behaviour: the SKILL.md describes automatic threshold checks and blocking writes, but there is no code showing how the skill integrates with the agent runtime. Verify how (and where) the auto-trigger hook runs; otherwise automatic prompting/blocking may not actually function or may rely on out-of-band integration. If you need the functionality, request the missing hawk-compress script or a packaged release (e.g., a complete wheel or single script) and a clear install manifest. Until the package is complete and the install effects are explicit, treat this skill as untrusted and test it in a sandboxed environment first.
Capability Analysis
Type: OpenClaw Skill Name: hawk-context Version: 1.1.0 The context-compressor skill is a utility designed to manage LLM token limits by summarizing chat history and preserving essential system prompts. The bundle includes a Python-based CLI tool (found in references/cli.md) for text processing and an installation script (scripts/install.sh) that adds the tool to the user's PATH via .bashrc. The logic is transparent, lacks network or sensitive file access, and contains no evidence of malicious intent or harmful prompt injection.
Capability Assessment
Purpose & Capability
The skill claims to be a pure-Python context compressor with a CLI (hawk-compress) and no external credentials or binaries required, which is reasonable. However README/SKILL.md and the install script expect a hawk-compress executable under scripts/ to be symlinked into ~/bin, but the file manifest does not include that executable — only scripts/install.sh is present. That missing binary is a clear mismatch between claimed capabilities and the provided files.
Instruction Scope
SKILL.md and references describe automatic triggering (every 10 rounds, threshold checks, blocking writes at high thresholds) and say compression will write a history file (memory/today.md). The instructions do not show how auto-trigger integrates with the agent/platform (no hook code or manifest integration), and they assume file writes to a 'memory' path. The runtime instructions also recommend modifying the user's shell (~/.bashrc) via the installer. These behaviors go beyond simply reading an input chat history and are not fully specified in the package.
Install Mechanism
There is no formal install spec, but an included scripts/install.sh will append to ~/.bashrc (adding ~/bin to PATH) and create a symlink from $SCRIPT_DIR/hawk-compress to ~/bin/hawk-compress. That is intrusive (modifies user shell startup files) and will fail or be misleading because the referenced hawk-compress file is missing from the manifest. The installer links from a relative path in the package directory, which could be harmless if the executable existed, but as-is it indicates incomplete packaging and risky modification of user config for no clear benefit.
Credentials
The skill requests no environment variables or credentials, which is proportional and good. However it writes compression history to memory/today.md (per README/structured-output) and modifies shell config via the installer; those side-effects are not declared in requires.config and should be considered by users, though they are not secret-exfiltration risks on their face.
Persistence & Privilege
always is false and the skill does not request elevated platform privileges. The installer creates persistent artifacts (~/bin/hawk-compress symlink and an appended PATH entry in ~/.bashrc) and the tool writes compression history to memory/today.md. These are persistent but limited to user files; still, modifying ~/.bashrc is a persistent change and should be made explicit and handled with caution.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install hawk-context
  3. After installation, invoke the skill by name or use /hawk-context
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.0
v1.1.0: add install.sh for auto symlink to ~/bin, update Quick Start docs
v1.0.0
v1.0.0: Real-time conversation context compression. Auto-trigger at 70%, 4 levels, structured JSON output, importance filtering, deduplication, pure Python.
Metadata
Slug hawk-context
Version 1.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 2
Frequently Asked Questions

What is Context Compressor?

Context Compressor — Real-time conversation context compression engine. Activates when user says "compress context", "压缩上下文", "上下文爆了", "context full", "上下文瘦身... It is an AI Agent Skill for Claude Code / OpenClaw, with 106 downloads so far.

How do I install Context Compressor?

Run "/install hawk-context" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Context Compressor free?

Yes, Context Compressor is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Context Compressor support?

Context Compressor is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Context Compressor?

It is built and maintained by Gao.QiLin (@relunctance); the current version is v1.1.0.

💬 Comments