Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add echoVic/blade-code --skill compaction-pipeline-and-checkpointsgit clone --depth 1 https://github.com/echoVic/blade-codeWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/echovic/blade-code/compaction-pipeline-and-checkpoints)<a href="https://agentmods.dev/skills/echovic/blade-code/compaction-pipeline-and-checkpoints"><img src="https://agentmods.dev/badge/skills/echovic/blade-code/compaction-pipeline-and-checkpoints.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00144 | $0.02387 |
| Opus 5 | $0.00072 | $0.01193 |
| Sonnet 5 | $0.00029 | $0.00477 |
| Haiku 4.5 | $0.00014 | $0.00239 |
Grade A, and why
knowledge-session-state-and-context-compaction-pipeline-and-checkpoints scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 64 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Module Structure
该节点控制单个 Session 发给 Provider 的有效上下文。它保留完整 JSONL 历史,只通过有版本的 replacement checkpoint 改变后续模型请求,并把任何可重放恢复限制在 Provider 尚未交付真实输出的边界内。
Directory Layout
packages/cli/src/context/ContextTokenTracker.ts:Provider usage 基线与下一请求占用投影packages/cli/src/context/TokenBudgetHandoff.ts:70% 交接和 80% 压缩状态机packages/cli/src/context/SnipCompaction.ts:旧工具轮次和 cache-expiry micro compactpackages/cli/src/context/CompactionService.ts:LLM 摘要、ledger、效果验证与失败熔断packages/cli/src/context/CompactionFallback.ts:无模型的 token-bound replacement plannerpackages/cli/src/context/ReactiveCompaction.ts:context-limit 错误的一次性紧急恢复packages/cli/src/context/compactionCheckpoint.ts:replacementMessages 的持久格式和边界packages/cli/src/context/ToolResultBudget.ts:单结果与单轮工具输出预算
Key Entry Points
checkAndCompactInLoop()inpackages/cli/src/agent/loop/executeLoopGenerator.ts:按固定层级协调压缩ContextTokenTracker.project()inpackages/cli/src/context/ContextTokenTracker.ts:生成 handoff/compaction 共用占用快照CompactionService.compact()inpackages/cli/src/context/CompactionService.ts:生成并验证 replacementPersistentStore.saveCompaction()inpackages/cli/src/context/storage/PersistentStore.ts:先持久化 checkpoint 再允许内存替换
Gotchas
- 预测式占用以
max(totalTokens, promptTokens + completionTokens)为 Provider floor,Provider 已计算的 assistant response 不能再次本地累加;只估算该响应之后的消息和固定 context 正向增长 (packages/cli/src/context/ContextTokenTracker.ts) - Provider usage 缺失、history 被破坏性重写、首个追加项不是 assistant 或 revision 不匹配时必须退回完整本地估算,不能沿用旧 baseline (
packages/cli/src/context/ContextTokenTracker.ts) - handoff/compaction 阈值基于
maxContextTokens - output reserve的输入预算,而非整个 context window;未显式给 output cap 时 reserve 为 10%,并限制在 8192 到 32768 (packages/cli/src/context/TokenBudgetHandoff.ts) - durable handoff 只允许出现在 70% 到 80% band,当前 compaction epoch 只能有一条严格 v1 记录;重复或畸形 raw record 会把该 epoch 标记 suppressed,而不是择一恢复 (
packages/cli/src/context/TokenBudgetHandoff.ts,git:4cf1fcba) - handoff 是只供模型继续任务的隐藏 user message:会持久化但不进入 client stream,fork 会剥离,compaction 输入也会先剥离;不要把它渲染成普通用户消息 (
packages/cli/src/context/TokenBudgetHandoff.ts,packages/cli/src/context/events/SessionEventLog.ts) checkAndCompactInLoop()的顺序是 cache-expiry micro compact、普通 snip、80% LLM compaction;snip 结果延迟应用,确保 LLM compaction 被取消或 checkpoint 失败时不会留下半更新内存 (packages/cli/src/agent/loop/executeLoopGenerator.ts)- 当 token snapshot 为 unknown 时仍可应用 micro/snip,但不会做 LLM compaction 或 handoff;没有 usage 不等于完全禁用本地瘦身 (
packages/cli/src/agent/loop/executeLoopGenerator.ts) - reactive compaction 每个成功 Provider boundary 只允许一次,并且仅在 context-limit 错误发生于任何 content/thinking/usage/tool-call 之前才可重放;跨过输出边界后必须 fail closed (
packages/cli/src/context/ReactiveCompaction.ts,packages/cli/src/agent/loop/executeLoopGenerator.ts) - compaction hook 可显式阻止压缩;该情况抛
CompactionBlockedError,reactive 路径返回失败且保留原上下文,不能伪造 fallback checkpoint (packages/cli/src/context/CompactionService.ts,packages/cli/src/context/ReactiveCompaction.ts) - 摘要采样内部关闭 SDK retry,只共享最多三次总预算;context overflow 的缩减顺序是移除可重读文件、丢弃最旧完整 message/tool unit、降低单消息字符上限,且每次输入必须严格变小 (
packages/cli/src/context/CompactionService.ts,git:2d8977b9) - LLM 返回非空摘要仍要通过效果门槛:大历史 replacement 不得超过源消息 80%,所有结果还受 context 50% 和 50,000 tokens 上限;缩减不足会记账后进入 fallback (
packages/cli/src/context/CompactionService.ts,packages/cli/src/context/CompactionFallback.ts,git:9889c4f0) - deterministic fallback 先预算 ledger 与 active-task checkpoint,再从最新端保留完整 message unit;assistant tool call 与对应 results 不拆分,边界只截一个 unit,reasoning 和图片载荷被移除或占位 (
packages/cli/src/context/CompactionFallback.ts) - mandatory active-task checkpoint 超过目标时会把目标提升到 checkpoint 实际大小,而不是静默删除用户约束;未截断 checkpoint 已覆盖的最后 user message 才会从 fallback tail 去重 (
packages/cli/src/context/CompactionFallback.ts,packages/cli/src/context/CompactionService.ts) - replacement 必须先通过
saveCompaction()fsync 到 JSONL,再替换内存并重试 Provider;checkpoint commit 失败时本轮以checkpointphase 失败,不能仅在内存继续 (packages/cli/src/agent/loop/conversationPersistence.ts,packages/cli/src/agent/loop/executeLoopGenerator.ts) - continuation ledger 的七个 heading 是宿主协议;显式
EXACT CONTINUATION RECORD会在模型摘要后由宿主去重并逐字归位,不能交给模型自由改写 (packages/cli/src/context/CompactionService.ts,git:86f49fec) - 最近文件恢复必须同时按 Session 与 active workspace 过滤,并拒绝 workspace 外路径和符号链接;先截前五条再过滤会饿死真正可恢复文件 (
packages/cli/src/context/CompactionService.ts,packages/cli/src/context/FileAnalyzer.ts)
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3d ago First seen · 64 lines · 144 tokens per session scan A 60e591549f19
knowledge-session-state-and-context-compaction-pipeline-and-checkpoints is a skill published in the GitHub repository echoVic/blade-code (178 stars, last pushed today), licensed MIT. It adds 144 tokens to every session and 2,387 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other skills, from other repositories
algorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright…
slack-gif-creator
Toolkit for creating animated GIFs optimized for Slack, with validators for size constraints and composable animation primitives. This skill applies when users request animated GIFs or emoji animations for Slack from descriptions like "make me a GIF for Slack of X doing Y".
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external agents through well-designed tools. Use when building MCP servers to integrate external APIs or agents, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
canvas-design
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.
self-improvement
A process for recording useful lessons from unexpected failures, user corrections, missing abilities, and reusable project patterns.
travel-planner
Creates comprehensive travel itineraries with destination analysis, budget planning, transportation, accommodation, and local insights. Use when planning trips, organizing travel schedules, or seeking destination recommendations.