一键导入
context-guard
Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
Unified context lifecycle for FlowDeck sessions — ingest, filter, prune, protect, summarize, and persist with telemetry.
Predict affected files, modules, APIs, tests, and DB paths before changes. Returns an impact map for human review.
Map architecture, conventions, and file structure into `.codebase/`. Use when onboarding or before deep feature work.
Plan differently when the agent has low certainty — ask for clarification or narrow scope instead of pretending full understanding.
Load full project context at session start. Read STATE.md, PLAN.md, PROJECT.md, CONVENTIONS.md, and ARCHITECTURE.md to brief any agent on where work stands.
| name | context-guard |
| description | Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors. |
| origin | FlowDeck |
Defines the protected-pattern contract: a whitelist of files, tools, decisions, and messages that must survive context compaction.
A protected pattern is any context item that a pruning pass must skip. Without it, compaction can silently discard the very state an agent needs to finish a task.
Four categories:
Tool invocations that must remain in the conversation window while they are in flight or unverified. Example: a write or edit call whose result has not yet been confirmed.
Paths that anchor the current session. These include active planning files, project conventions, and safety ledgers.
Records that explain why the session is in its current state. Removing them forces the agent to re-derive intent from scratch.
User messages that establish the original goal and the most recent steering corrections. These are the cheapest way to prevent drift.
FlowDeck ships with a default registry. Override it in .opencode/flowdeck/protected-patterns.yaml, never by editing this skill.
| Pattern | Reason |
|---|---|
AGENTS.md | Operating rules for every agent |
~/.fd-plan/<slug>/STATE.md | Current phase, completed steps, blockers |
~/.fd-plan/<slug>/<topic>/plan.md | Active plan and success criteria |
| Pattern | Reason |
|---|---|
.codebase/DECISIONS.jsonl | Decision ledger — why choices were made |
.codebase/FAILURES.json | Failure replay engine data |
| Pattern | Reason |
|---|---|
| Last 2 user messages | Original goal + latest steering |
| Current phase objective | From STATE.md — the single sentence that defines success |
Any pending tool whose side effects have not been verified:
| Tool | Condition |
|---|---|
write | while pending verification |
edit | while pending verification |
bash | while exit code/output not yet checked |
Before any pruning or compaction run, context-steward executes this protocol:
Only items that survive the guard pass are eligible for compaction. The protocol is fail-closed: when in doubt, protect.
Create .opencode/flowdeck/protected-patterns.yaml:
protected:
files:
- pattern: "~/.fd-plan/<slug>/STATE.md"
reason: "session state"
- pattern: "~/.fd-plan/<slug>/<topic>/plan.md"
reason: "active plan"
- pattern: ".codebase/DECISIONS.jsonl"
reason: "decision ledger"
- pattern: ".codebase/FAILURES.json"
reason: "failure replay data"
- pattern: "AGENTS.md"
reason: "agent operating rules"
tools:
- name: "write"
while: "pending"
- name: "edit"
while: "pending"
- name: "bash"
while: "pending"
messages:
- type: "user"
count: 2
decisions:
- source: ".codebase/DECISIONS.jsonl"
count: 5
context-stewardcontext-steward calls context-guard before every compaction pass:
Users do not call context-guard directly. It is a dependency of the compaction pipeline.
.opencode/flowdeck/protected-patterns.yamlProject patterns are appropriate for:
MIGRATIONS.md, SCHEMA.md)Do not add transient build artifacts or cache files. Those are noise, not signal.
If every file and message is protected, compaction becomes a no-op. The registry exists to make pruning safe, not to disable it. Protect only items whose loss would force the agent to restart the task.
A pattern like STATE.md misses ~/.fd-plan/<slug>/STATE.md. A pattern like PLAN.md misses phase-specific plans at ~/.fd-plan/<slug>/phases/phase-3/PLAN.md. Use glob-style or prefix patterns so protection survives path changes.
A write call that has been verified, or a temporary scratch file from a completed operation, should not remain in the registry. Temporary protection must expire when the operation completes.
Large outputs (git diff, test logs, MCP responses) are usually not state. Summarize them and protect the summary, not the full output.
| Pattern Type | Example | Keep Condition |
|---|---|---|
| File | ~/.fd-plan/<slug>/STATE.md | Always |
| File | .codebase/DECISIONS.jsonl | Always |
| Tool | write | While pending |
| Tool | edit | While pending |
| Message | User turn | Last 2 |
| Decision | .codebase/DECISIONS.jsonl | Last 5 entries |
context-load — what to load at session startcontext-budget — when and why to compact