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 session-state-and-contextgit 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/session-state-and-context)<a href="https://agentmods.dev/skills/echovic/blade-code/session-state-and-context"><img src="https://agentmods.dev/badge/skills/echovic/blade-code/session-state-and-context.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.00133 | $0.01756 |
| Opus 5 | $0.00067 | $0.00878 |
| Sonnet 5 | $0.00027 | $0.00351 |
| Haiku 4.5 | $0.00013 | $0.00176 |
Grade A, and why
knowledge-session-state-and-context 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.
Copies of this mod
7 near-identical copies found in the catalogue:
- knowledge-runtime-state-bootstrap-and-observability — 89% identical, 146 lines differ
- knowledge-session-state-and-context-context-compaction-token-budget-and-memory — 88% identical, 73 lines differ
- knowledge-session-state-and-context-durable-transcript-and-event-projection — 84% identical, 138 lines differ
- knowledge-permissions-and-workspace-trust — 81% identical, 106 lines differ
- knowledge-session-state-and-context-project-auto-memory — 80% identical, 75 lines differ
- knowledge-capacity-lifecycle-and-egress — 80% identical, 117 lines differ
- knowledge-workspace-policy-and-shared-foundations — 80% identical, 103 lines differ
How it starts
The opening of the file, as written. The whole thing — 55 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Module Structure
该域负责把一次会话的权威事实、活动运行时与各端读模型分开:持久事实进入 JSONL,运行时持有互斥与恢复状态,TUI/Web/ACP 从相同事实投影,模型上下文则可在不破坏完整历史的前提下压缩。
Directory Layout
packages/cli/src/context/:事件模型、持久存储、上下文组装、压缩与 Token 预算packages/cli/src/agent/runtime/:Session 所有权、活动轮次 mailbox、恢复和私有 artifactpackages/cli/src/services/SessionService.ts:会话目录、加载、分叉、回退、归档与导出编排packages/cli/src/services/SessionInteractionService.ts:持久交互请求、响应和崩溃恢复packages/cli/src/memory/:跨会话项目记忆与压缩后巩固
Key Entry Points
SessionRuntime.initialize()inpackages/cli/src/agent/runtime/SessionRuntime.ts:获取会话所有权并执行恢复PersistentStoreinpackages/cli/src/context/storage/PersistentStore.ts:将领域动作转换为有序事件SessionServiceinpackages/cli/src/services/SessionService.ts:面向 CLI、Web 与 ACP 的持久会话服务CompactionService.compact()inpackages/cli/src/context/CompactionService.ts:生成并约束模型可见替换上下文
Gotchas
sessionId不是全局身份;省略projectPath的查找可能因多个工作区同名而拒绝,跨端路由必须保持sessionId + canonical projectPath复合身份 (packages/cli/src/services/SessionService.ts,packages/cli/src/server/sessionRef.ts)- Runtime、TUI store、Web store 和 SQLite 都不是持久真相,修复恢复问题时必须从 materialized JSONL 重新推导,不能把某个内存快照写回当作权威 (
packages/cli/src/context/storage/PersistentStore.ts,packages/cli/src/context/storage/sqlite/projection.ts) - rewind 与 compaction 都保留原始 transcript:前者通过
session_rewound改变有效事件,后者通过 replacement checkpoint 改变模型可见上下文;直接截断 JSONL 会同时破坏审计、导出和断点续传 (packages/cli/src/services/sessionRewind.ts,packages/cli/src/services/SessionService.ts) - durable inbox、prompt artifact 等 sidecar 不是独立会话真相;它们必须通过 transcript 中的 acknowledgement、message metadata 或生命周期事件对账后才能删除或重放 (
packages/cli/src/agent/runtime/DurableSteeringInbox.ts,packages/cli/src/agent/runtime/UserPromptArtifactStore.ts) - 会话恢复必须先取得
SessionLease再修复 orphan 进程、工具调用和 turn;颠倒顺序会让两个进程同时“恢复”同一条父链 (packages/cli/src/agent/runtime/SessionRuntime.ts,packages/cli/src/agent/runtime/SessionLease.ts,git:46145c53)
Architecture
- 写路径为
SessionRuntime/SessionService -> ContextManager/PersistentStore -> SessionEventLog -> JSONLStore,事件落盘并取得 seq 后才允许发布给各 surface (packages/cli/src/agent/runtime/SessionRuntime.ts,packages/cli/src/context/ContextManager.ts,packages/cli/src/context/events/SessionEventLog.ts) - 读路径有三种不同投影:完整可见历史供 UI/导出,replacement checkpoint 之后的上下文供模型,SQLite materialization 供目录与搜索;三者不能互相替代 (
packages/cli/src/services/SessionService.ts,packages/cli/src/context/storage/sqlite/projection.ts) - 活动轮次采用“双账本”恢复:inbox 保存尚未确认的输入,JSONL 保存 turn/tool/interaction 事实;启动时通过 message ID 和终态 receipt 对账形成 exactly-once continuation (
packages/cli/src/agent/runtime/DurableSteeringInbox.ts,packages/cli/src/context/storage/PersistentStore.ts) - 跨端一致性依赖同一事件语义而非同一 UI reducer:TUI 使用共享 conversation reducer,Web 消费 SSE 投影,ACP 消费顺序化 update,但都以已提交 JSONL 生命周期为恢复边界 (
packages/cli/src/store/slices/sessionSlice.ts,packages/cli/web/src/store/session/handlers/eventHandlers.ts,packages/cli/src/acp/Session.ts)
What ships with it
6 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
- active-turn-interactions-and-recovery/SKILL.md 11 KB
- context-compaction-token-budget-and-memory/compaction-pipeline-and-checkpoints/SKILL.md 9.4 KB
- context-compaction-token-budget-and-memory/project-auto-memory/SKILL.md 7.1 KB
- context-compaction-token-budget-and-memory/SKILL.md 7.5 KB
- durable-transcript-and-event-projection/SKILL.md 11 KB
- session-catalog-fork-rewind-and-export/SKILL.md 9.8 KB
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 · 55 lines · 133 tokens per session scan A 6737b8a5a85c
knowledge-session-state-and-context is a skill published in the GitHub repository echoVic/blade-code (178 stars, last pushed yesterday), licensed MIT. It adds 133 tokens to every session and 1,756 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
linearis
Manage Linear.app work from the command line with the linearis CLI (bins linearis / linear), which outputs JSON: issues/tickets, projects, cycles (sprints), milestones, initiatives (roadmap), documents, labels, teams, users, and issue discussions/comments. Use when the user mentions Linear, a ticket identifier like…
autogpt-agents
Autonomous AI agent platform for building and deploying continuous agents. Use when creating visual workflow agents, deploying persistent autonomous agents, or building complex multi-step AI automation systems.
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…
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).
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".
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.