@dv.nghiem/flowdeck 0.4.11 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/agents/orchestrator.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/schema.d.ts +27 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/dashboard/lib/state-reader.d.ts +2 -1
- package/dist/dashboard/lib/state-reader.d.ts.map +1 -1
- package/dist/dashboard/server.mjs +128 -13
- package/dist/dashboard/types.d.ts +12 -0
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/hooks/approval-hook.d.ts +16 -2
- package/dist/hooks/approval-hook.d.ts.map +1 -1
- package/dist/hooks/compaction-hook.d.ts +1 -1
- package/dist/hooks/compaction-hook.d.ts.map +1 -1
- package/dist/hooks/context-window-monitor.d.ts +7 -1
- package/dist/hooks/context-window-monitor.d.ts.map +1 -1
- package/dist/hooks/decision-trace-hook.d.ts +3 -0
- package/dist/hooks/decision-trace-hook.d.ts.map +1 -1
- package/dist/hooks/event-log-hook.d.ts +19 -3
- package/dist/hooks/event-log-hook.d.ts.map +1 -1
- package/dist/hooks/guard-rails.d.ts +16 -5
- package/dist/hooks/guard-rails.d.ts.map +1 -1
- package/dist/hooks/orchestrator-guard-hook.d.ts +8 -5
- package/dist/hooks/orchestrator-guard-hook.d.ts.map +1 -1
- package/dist/hooks/shell-env-hook.d.ts.map +1 -1
- package/dist/hooks/tool-guard.d.ts +19 -3
- package/dist/hooks/tool-guard.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8401 -4863
- package/dist/services/agent-contract-registry.d.ts.map +1 -1
- package/dist/services/agent-trace-graph.d.ts +4 -0
- package/dist/services/agent-trace-graph.d.ts.map +1 -1
- package/dist/services/agent-validator.d.ts +2 -1
- package/dist/services/agent-validator.d.ts.map +1 -1
- package/dist/services/approval-manager.d.ts +14 -1
- package/dist/services/approval-manager.d.ts.map +1 -1
- package/dist/services/audit-log.d.ts +23 -0
- package/dist/services/audit-log.d.ts.map +1 -0
- package/dist/services/context-ingress.d.ts +75 -0
- package/dist/services/context-ingress.d.ts.map +1 -0
- package/dist/services/deadlock-detector.d.ts.map +1 -1
- package/dist/services/delegation-budget.d.ts +55 -0
- package/dist/services/delegation-budget.d.ts.map +1 -0
- package/dist/services/event-logger.d.ts +3 -1
- package/dist/services/event-logger.d.ts.map +1 -1
- package/dist/services/execution-substrate.d.ts +35 -0
- package/dist/services/execution-substrate.d.ts.map +1 -0
- package/dist/services/harness-controller.d.ts +58 -0
- package/dist/services/harness-controller.d.ts.map +1 -0
- package/dist/services/harness-policy.d.ts +24 -0
- package/dist/services/harness-policy.d.ts.map +1 -0
- package/dist/services/harness-types.d.ts +178 -0
- package/dist/services/harness-types.d.ts.map +1 -0
- package/dist/services/lazy-rule-loader.d.ts +2 -0
- package/dist/services/lazy-rule-loader.d.ts.map +1 -1
- package/dist/services/loop-detector.d.ts.map +1 -1
- package/dist/services/prompt-cache.d.ts +25 -0
- package/dist/services/prompt-cache.d.ts.map +1 -0
- package/dist/services/recovery-layer.d.ts +26 -0
- package/dist/services/recovery-layer.d.ts.map +1 -0
- package/dist/services/run-trace.d.ts +17 -0
- package/dist/services/run-trace.d.ts.map +1 -1
- package/dist/services/state-persistence.d.ts +22 -0
- package/dist/services/state-persistence.d.ts.map +1 -0
- package/dist/services/supervisor-binding.d.ts +9 -0
- package/dist/services/supervisor-binding.d.ts.map +1 -1
- package/dist/services/token-metrics.d.ts +39 -0
- package/dist/services/token-metrics.d.ts.map +1 -0
- package/dist/services/verification-layer.d.ts +24 -0
- package/dist/services/verification-layer.d.ts.map +1 -0
- package/dist/services/workflow-scorecard.d.ts +5 -0
- package/dist/services/workflow-scorecard.d.ts.map +1 -1
- package/dist/tools/decision-trace.d.ts +4 -0
- package/dist/tools/decision-trace.d.ts.map +1 -1
- package/dist/tools/delegate.d.ts +16 -0
- package/dist/tools/delegate.d.ts.map +1 -0
- package/dist/tools/failure-replay.d.ts +8 -0
- package/dist/tools/failure-replay.d.ts.map +1 -1
- package/dist/tools/policy-engine.d.ts +1 -0
- package/dist/tools/policy-engine.d.ts.map +1 -1
- package/docs/concepts/HARNESS_ARCHITECTURE.md +241 -0
- package/docs/concepts/HARNESS_LAYERS.md +378 -0
- package/docs/concepts/HARNESS_WIRING.md +404 -0
- package/docs/getting-started/installation.md +0 -18
- package/docs/index.md +0 -1
- package/docs/reference/hooks.md +1 -16
- package/package.json +6 -6
- package/src/commands/fd-guarded-edit.md +69 -0
- package/src/rules/common/agent-defense.md +66 -0
- package/src/rules/common/agent-orchestration.md +35 -1
- package/src/skills/context-budget/SKILL.md +266 -0
- package/src/skills/context-guard/SKILL.md +172 -0
- package/src/skills/context-steward/SKILL.md +297 -0
- package/src/skills/decision-trace/SKILL.md +137 -0
- package/src/skills/research-first/SKILL.md +344 -0
- package/src/skills/session-persistence/SKILL.md +320 -0
- package/src/skills/telemetry-steward/SKILL.md +191 -0
- package/dist/services/rtk-manager.d.ts +0 -80
- package/dist/services/rtk-manager.d.ts.map +0 -1
- package/dist/services/rtk-policy.d.ts +0 -26
- package/dist/services/rtk-policy.d.ts.map +0 -1
- package/dist/tools/rtk-setup.d.ts +0 -22
- package/dist/tools/rtk-setup.d.ts.map +0 -1
- package/docs/reference/rtk.md +0 -162
|
@@ -51,6 +51,40 @@ The orchestrator NEVER:
|
|
|
51
51
|
| `@tester` | Write and run tests (TDD) | Implementing features or fixing bugs |
|
|
52
52
|
| `@writer` | Draft project documentation | Writing or updating docs |
|
|
53
53
|
|
|
54
|
+
## Agent Categories
|
|
55
|
+
|
|
56
|
+
Agents are grouped into categories for flexible routing:
|
|
57
|
+
|
|
58
|
+
| Category | Agents | Purpose |
|
|
59
|
+
|----------|--------|---------|
|
|
60
|
+
| `cognition` | `@architect`, `@planner`, `@code-explorer` | Deep reasoning, design, and exploration |
|
|
61
|
+
| `execution` | `@backend-coder`, `@frontend-coder`, `@devops`, `@default-executor` | Implementation and delivery |
|
|
62
|
+
| `verification` | `@tester`, `@reviewer`, `@security-auditor`, `@build-error-resolver` | Quality assurance and validation |
|
|
63
|
+
| `governance` | `@orchestrator`, `@discusser`, `@plan-checker`, `@task-splitter`, `@doc-updater`, `@writer` | Process coordination and documentation |
|
|
64
|
+
| `specialist` | `@debug-specialist`, `@performance-optimizer`, `@refactor-guide`, `@researcher`, `@mapper` | Domain-specific expertise |
|
|
65
|
+
|
|
66
|
+
## Category-Based Routing
|
|
67
|
+
|
|
68
|
+
The orchestrator may route to a **category** instead of a named agent. Categories resolve to a default agent but can be overridden in `flowdeck.json`.
|
|
69
|
+
|
|
70
|
+
| Category | Default Agent |
|
|
71
|
+
|----------|--------------|
|
|
72
|
+
| `cognition` | `@planner` |
|
|
73
|
+
| `execution` | `@backend-coder` |
|
|
74
|
+
| `verification` | `@reviewer` |
|
|
75
|
+
| `governance` | `@orchestrator` |
|
|
76
|
+
| `specialist` | `@researcher` |
|
|
77
|
+
|
|
78
|
+
### Routing Examples
|
|
79
|
+
|
|
80
|
+
- **Build failure** signal → `verification` category → default `@build-error-resolver`
|
|
81
|
+
- **Complex feature** request → `cognition` category → default `@planner`, then hands off to `execution`
|
|
82
|
+
- **Security concern** → `verification` category → default `@security-auditor` (override in config if needed)
|
|
83
|
+
|
|
84
|
+
Category routing decouples workflow definitions from specific agent identities, making workflows more portable across projects.
|
|
85
|
+
|
|
86
|
+
> **Note:** Agent names are stable; categories are configurable. Prefer routing by category in workflow skills.
|
|
87
|
+
|
|
54
88
|
## Execution Paths
|
|
55
89
|
|
|
56
90
|
After the orchestrator analyzes and classifies a request, it selects ONE execution path:
|
|
@@ -89,7 +123,7 @@ For normal or complex tasks:
|
|
|
89
123
|
|
|
90
124
|
## When to Use Agents Immediately
|
|
91
125
|
|
|
92
|
-
These situations should trigger agent use automatically:
|
|
126
|
+
These situations should trigger agent use automatically. When the specific agent is unclear, route by **category** instead:
|
|
93
127
|
|
|
94
128
|
| Situation | Agent |
|
|
95
129
|
|-----------|-------|
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: context-budget
|
|
3
|
+
description: Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
|
|
4
|
+
origin: FlowDeck
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Context Budget Skill
|
|
8
|
+
|
|
9
|
+
Treat context window as a finite resource. Every token loaded — files, rules, tool outputs, conversation history — consumes budget. Optimizing context improves speed, cuts costs, and prevents mid-session truncation.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
Activate when:
|
|
14
|
+
- A session exceeds 50K tokens or feels sluggish
|
|
15
|
+
- You are about to load large files, MCP tools, or heavy rulesets
|
|
16
|
+
- You want to audit and slim down your FlowDeck setup
|
|
17
|
+
- You are designing new skills, agents, or workflows
|
|
18
|
+
|
|
19
|
+
## Core Principles
|
|
20
|
+
|
|
21
|
+
- **Load less, get more** — context quality beats context quantity
|
|
22
|
+
- **Measure before optimizing** — know your current burn rate
|
|
23
|
+
- **Batch over chat** — accumulate work, run checks once
|
|
24
|
+
- **Right-size the model** — light tasks do not need the strongest model
|
|
25
|
+
|
|
26
|
+
## Why Context Budget Matters
|
|
27
|
+
|
|
28
|
+
| Factor | Impact |
|
|
29
|
+
|--------|--------|
|
|
30
|
+
| Context window limit | Hard cap — exceed it and early conversation is lost |
|
|
31
|
+
| Cost per token | More context = more input tokens = higher bill |
|
|
32
|
+
| Response latency | Large context increases time-to-first-token |
|
|
33
|
+
| Attention degradation | Models perform worse on content near the middle of long context |
|
|
34
|
+
|
|
35
|
+
### Hard Limits (Examples)
|
|
36
|
+
|
|
37
|
+
| Model | Context Window |
|
|
38
|
+
|-------|---------------|
|
|
39
|
+
| Claude 3.5 Haiku | 200K tokens |
|
|
40
|
+
| Claude 3.5 Sonnet | 200K tokens |
|
|
41
|
+
| GPT-4o | 128K tokens |
|
|
42
|
+
| GPT-4o mini | 128K tokens |
|
|
43
|
+
|
|
44
|
+
Treat 80% of the window as your practical maximum. Beyond that, truncation risk rises sharply.
|
|
45
|
+
|
|
46
|
+
## Skill Size Audit
|
|
47
|
+
|
|
48
|
+
Oversized skills waste context on every activation. Audit yours regularly.
|
|
49
|
+
|
|
50
|
+
### Thresholds
|
|
51
|
+
|
|
52
|
+
| Metric | Warning | Critical |
|
|
53
|
+
|--------|---------|----------|
|
|
54
|
+
| Lines per SKILL.md | > 300 | > 400 |
|
|
55
|
+
| Words in description | > 25 | > 30 |
|
|
56
|
+
| Files loaded per task | > 5 | > 10 |
|
|
57
|
+
| Rules active at once | > 8 | > 12 |
|
|
58
|
+
|
|
59
|
+
### How to Audit
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Count lines in all skills
|
|
63
|
+
find src/skills -name "SKILL.md" -exec wc -l {} + | sort -n
|
|
64
|
+
|
|
65
|
+
# Flag skills over 300 lines
|
|
66
|
+
find src/skills -name "SKILL.md" -exec sh -c 'lines=$(wc -l < "$1"); [ "$lines" -gt 300 ] && echo "$lines $1"' _ {} \;
|
|
67
|
+
|
|
68
|
+
# Check description word counts
|
|
69
|
+
grep -r "^description:" src/skills/ | awk '{print NF, $0}' | sort -n
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Remediation
|
|
73
|
+
|
|
74
|
+
- **Split oversized skills** — extract sub-topics into separate skills
|
|
75
|
+
- **Shorten descriptions** — under 25 words is ideal; under 30 is required
|
|
76
|
+
- **Use stage-gated rules** — load heavy rules only in `execute` or `verify` stages
|
|
77
|
+
- **Defer heavy context** — load `.codebase/ARCHITECTURE.md` only when needed
|
|
78
|
+
|
|
79
|
+
## Model Routing Strategy
|
|
80
|
+
|
|
81
|
+
Not every task needs the strongest model. Route by complexity.
|
|
82
|
+
|
|
83
|
+
| Task Type | Example | Model Tier |
|
|
84
|
+
|-----------|---------|-----------|
|
|
85
|
+
| Simple edit | Fix typo, rename variable | Fast / Small |
|
|
86
|
+
| Code review | Lint, style check | Fast / Small |
|
|
87
|
+
| Research | Look up API docs | Fast / Small |
|
|
88
|
+
| Feature implementation | Multi-file change | Strong / Large |
|
|
89
|
+
| Debug | Root cause analysis | Strong / Large |
|
|
90
|
+
| Architecture design | New module design | Strong / Large |
|
|
91
|
+
|
|
92
|
+
### FlowDeck Agent Routing
|
|
93
|
+
|
|
94
|
+
FlowDeck already routes by task class:
|
|
95
|
+
- `quick` workflow → `@default-executor` (lightweight)
|
|
96
|
+
- `standard` workflow → specialist agents (medium)
|
|
97
|
+
- `verify-heavy` or `explore` → strongest models (heavy)
|
|
98
|
+
|
|
99
|
+
Respect this routing. Do not escalate a `quick` task to a heavy agent.
|
|
100
|
+
|
|
101
|
+
## Prefer CLI Tools Over MCPs
|
|
102
|
+
|
|
103
|
+
MCP servers add context overhead: schema discovery, tool definitions, and response envelopes. Native CLI tools are leaner.
|
|
104
|
+
|
|
105
|
+
| Use Case | Heavy MCP | Lean Alternative |
|
|
106
|
+
|----------|-----------|-----------------|
|
|
107
|
+
| Git operations | GitHub MCP | `git`, `gh` CLI |
|
|
108
|
+
| AWS queries | AWS MCP | `aws` CLI |
|
|
109
|
+
| Kubernetes checks | K8s MCP | `kubectl` |
|
|
110
|
+
| File search | File-system MCP | `find`, `rg` |
|
|
111
|
+
| Database query | DB MCP | `psql`, `mysql` CLI |
|
|
112
|
+
|
|
113
|
+
### When MCPs Are Worth It
|
|
114
|
+
|
|
115
|
+
- Complex multi-step operations (e.g., create PR + add reviewers + set labels)
|
|
116
|
+
- Operations requiring authentication tokens you do not have locally
|
|
117
|
+
- Structured data return that CLI would require parsing
|
|
118
|
+
|
|
119
|
+
## Accumulator + Batch Pattern
|
|
120
|
+
|
|
121
|
+
Chatty sessions burn context fast. Accumulate edits, then run checks once.
|
|
122
|
+
|
|
123
|
+
### Anti-Pattern: Chatty Loop
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Edit file A → run test → fix error → edit file B → run test → fix error → edit file C → run test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Each test run consumes output tokens. Three runs = 3x test output in context.
|
|
130
|
+
|
|
131
|
+
### Preferred: Batch + Single Check
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
Edit file A
|
|
135
|
+
Edit file B
|
|
136
|
+
Edit file C
|
|
137
|
+
Run tests once
|
|
138
|
+
Fix all errors
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### In FlowDeck
|
|
142
|
+
|
|
143
|
+
Use `/fd-checkpoint` after a batch of edits, then `/fd-resume` to continue. This preserves your work without carrying full error output forward indefinitely.
|
|
144
|
+
|
|
145
|
+
## Strategic Context Clearing
|
|
146
|
+
|
|
147
|
+
Long sessions accumulate noise: failed attempts, dead-ends, large tool outputs. Clear context before it degrades quality.
|
|
148
|
+
|
|
149
|
+
### When to Checkpoint
|
|
150
|
+
|
|
151
|
+
| Signal | Action |
|
|
152
|
+
|--------|--------|
|
|
153
|
+
| Session > 1 hour | `/fd-checkpoint` |
|
|
154
|
+
| Tokens > 50K | `/fd-checkpoint` |
|
|
155
|
+
| Multiple failed attempts | `/fd-checkpoint` and reassess |
|
|
156
|
+
| Task complete, new task next | `/fd-checkpoint` |
|
|
157
|
+
|
|
158
|
+
### Resume Pattern
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
1. `/fd-checkpoint` — save current state to STATE.md
|
|
162
|
+
2. Start fresh session
|
|
163
|
+
3. `/fd-resume` — load STATE.md, PLAN.md, active context
|
|
164
|
+
4. Continue with clean context
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
This is cheaper than carrying 80K tokens of conversation history.
|
|
168
|
+
|
|
169
|
+
## Rule Loading Optimization
|
|
170
|
+
|
|
171
|
+
FlowDeck uses stage-gated rules. Only rules matching the current stage are loaded.
|
|
172
|
+
|
|
173
|
+
| Stage | Typical Rules Loaded |
|
|
174
|
+
|-------|---------------------|
|
|
175
|
+
| `discuss` | Behavioral, lightweight |
|
|
176
|
+
| `plan` | Planning, architecture |
|
|
177
|
+
| `execute` | Coding standards, language patterns, security |
|
|
178
|
+
| `verify` | Testing, security, linting |
|
|
179
|
+
| `fix-bug` | Debug, testing |
|
|
180
|
+
|
|
181
|
+
### Keep Rules Focused
|
|
182
|
+
|
|
183
|
+
- One concern per rule file
|
|
184
|
+
- Use `stages` array to gate loading
|
|
185
|
+
- Set `always_on: false` for heavy rules
|
|
186
|
+
- Keep rules under 150 lines when possible
|
|
187
|
+
|
|
188
|
+
Audit with:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Find rules loaded in every stage (always_on = true)
|
|
192
|
+
grep -r "always_on: true" src/rules/
|
|
193
|
+
|
|
194
|
+
# Find oversized rules
|
|
195
|
+
find src/rules -name "*.md" -exec sh -c 'lines=$(wc -l < "$1"); [ "$lines" -gt 200 ] && echo "$lines $1"' _ {} \;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Code Modularity Benefits
|
|
199
|
+
|
|
200
|
+
Smaller files = less context per task. A 400-line file forces the model to hold the entire file in working memory. Four 100-line files let the model focus on one at a time.
|
|
201
|
+
|
|
202
|
+
| File Size | Context Impact |
|
|
203
|
+
|-----------|---------------|
|
|
204
|
+
| < 200 lines | Minimal — load on demand |
|
|
205
|
+
| 200-400 lines | Moderate — acceptable for core files |
|
|
206
|
+
| 400-800 lines | Heavy — consider splitting |
|
|
207
|
+
| > 800 lines | Critical — split immediately |
|
|
208
|
+
|
|
209
|
+
### Splitting Guidance
|
|
210
|
+
|
|
211
|
+
- One responsibility per file
|
|
212
|
+
- Extract utilities to `utils/` or `helpers/`
|
|
213
|
+
- Extract types to `types.ts`
|
|
214
|
+
- Use `codegraph` to find natural split points: `codegraph_impact` on a large symbol reveals which parts are independent
|
|
215
|
+
|
|
216
|
+
## Self-Audit Checklist
|
|
217
|
+
|
|
218
|
+
Run this monthly or when context feels heavy:
|
|
219
|
+
|
|
220
|
+
### Skills
|
|
221
|
+
- [ ] No SKILL.md exceeds 400 lines
|
|
222
|
+
- [ ] No skill description exceeds 30 words
|
|
223
|
+
- [ ] Unused skills removed from `.opencode/skills/`
|
|
224
|
+
|
|
225
|
+
### Rules
|
|
226
|
+
- [ ] No rule file exceeds 200 lines
|
|
227
|
+
- [ ] Heavy rules are stage-gated (`always_on: false`)
|
|
228
|
+
- [ ] No redundant rules (same topic, different files)
|
|
229
|
+
|
|
230
|
+
### Workflows
|
|
231
|
+
- [ ] Tasks are batched before verification runs
|
|
232
|
+
- [ ] `/fd-checkpoint` used at natural boundaries
|
|
233
|
+
- [ ] Model routing respects task complexity
|
|
234
|
+
|
|
235
|
+
### Codebase
|
|
236
|
+
- [ ] No source file exceeds 800 lines
|
|
237
|
+
- [ ] Core modules are under 400 lines
|
|
238
|
+
- [ ] Large files have clear split candidates via `codegraph`
|
|
239
|
+
|
|
240
|
+
### Session Hygiene
|
|
241
|
+
- [ ] MCP tools used only when CLI is insufficient
|
|
242
|
+
- [ ] Large outputs (logs, diffs) are summarized, not pasted raw
|
|
243
|
+
- [ ] Failed attempts are checkpointed, not retried endlessly
|
|
244
|
+
|
|
245
|
+
## Quick Wins
|
|
246
|
+
|
|
247
|
+
1. **Truncate diffs** — `git diff | head -50` instead of full diff
|
|
248
|
+
2. **Summarize logs** — `tail -20` instead of full log file
|
|
249
|
+
3. **Use `codegraph_search`** — find symbols without reading entire files
|
|
250
|
+
4. **Load rules on demand** — `load-rules` instead of pre-loading everything
|
|
251
|
+
5. **Split before you grow** — when a file hits 400 lines, plan the split
|
|
252
|
+
|
|
253
|
+
## Related Skills
|
|
254
|
+
|
|
255
|
+
- [`plan-task`](./plan-task/SKILL.md) — break work into right-sized chunks
|
|
256
|
+
- [`performance-profiling`](./performance-profiling/SKILL.md) — measure before optimizing
|
|
257
|
+
- [`context-load`](./context-load/SKILL.md) — load only the context you need
|
|
258
|
+
|
|
259
|
+
## References
|
|
260
|
+
|
|
261
|
+
- `/fd-checkpoint` — save session state, clear context
|
|
262
|
+
- `/fd-resume` — restore from checkpoint
|
|
263
|
+
- `load-rules` — stage-gated rule loading
|
|
264
|
+
- `codegraph` — symbol search without full-file reads
|
|
265
|
+
- `codegraph_impact` — find split points in large files
|
|
266
|
+
- `codegraph_search` — locate symbols efficiently
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: context-guard
|
|
3
|
+
description: Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
|
|
4
|
+
origin: FlowDeck
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Context Guard Skill
|
|
8
|
+
|
|
9
|
+
Defines the protected-pattern contract: a whitelist of files, tools, decisions, and messages that must survive context compaction.
|
|
10
|
+
|
|
11
|
+
## What Is a Protected Pattern?
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
Four categories:
|
|
16
|
+
|
|
17
|
+
### Tool Patterns
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
|
|
21
|
+
### File Patterns
|
|
22
|
+
|
|
23
|
+
Paths that anchor the current session. These include active planning files, project conventions, and safety ledgers.
|
|
24
|
+
|
|
25
|
+
### Decision Records
|
|
26
|
+
|
|
27
|
+
Records that explain why the session is in its current state. Removing them forces the agent to re-derive intent from scratch.
|
|
28
|
+
|
|
29
|
+
### Intent Anchors
|
|
30
|
+
|
|
31
|
+
User messages that establish the original goal and the most recent steering corrections. These are the cheapest way to prevent drift.
|
|
32
|
+
|
|
33
|
+
## Default Protected-Pattern Registry
|
|
34
|
+
|
|
35
|
+
FlowDeck ships with a default registry. Override it in `.opencode/flowdeck/protected-patterns.yaml`, never by editing this skill.
|
|
36
|
+
|
|
37
|
+
### System Files
|
|
38
|
+
|
|
39
|
+
| Pattern | Reason |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `AGENTS.md` | Operating rules for every agent |
|
|
42
|
+
| `.planning/STATE.md` | Current phase, completed steps, blockers |
|
|
43
|
+
| `.planning/PLAN.md` | Active plan and success criteria |
|
|
44
|
+
|
|
45
|
+
### Safety Files
|
|
46
|
+
|
|
47
|
+
| Pattern | Reason |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `.codebase/DECISIONS.jsonl` | Decision ledger — why choices were made |
|
|
50
|
+
| `.codebase/FAILURES.json` | Failure replay engine data |
|
|
51
|
+
|
|
52
|
+
### Intent Anchors
|
|
53
|
+
|
|
54
|
+
| Pattern | Reason |
|
|
55
|
+
|---|---|
|
|
56
|
+
| Last 2 user messages | Original goal + latest steering |
|
|
57
|
+
| Current phase objective | From STATE.md — the single sentence that defines success |
|
|
58
|
+
|
|
59
|
+
### Active Operations
|
|
60
|
+
|
|
61
|
+
Any pending tool whose side effects have not been verified:
|
|
62
|
+
|
|
63
|
+
| Tool | Condition |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `write` | while pending verification |
|
|
66
|
+
| `edit` | while pending verification |
|
|
67
|
+
| `bash` | while exit code/output not yet checked |
|
|
68
|
+
|
|
69
|
+
## Guard Protocol
|
|
70
|
+
|
|
71
|
+
Before any pruning or compaction run, `context-steward` executes this protocol:
|
|
72
|
+
|
|
73
|
+
1. **Enumerate** — load the default registry and any user overrides
|
|
74
|
+
2. **Resolve** — expand patterns to concrete files, tool IDs, and message indices
|
|
75
|
+
3. **Check** — for every candidate marked for removal, test against the registry
|
|
76
|
+
4. **Block** — if the candidate matches a protected pattern, keep it
|
|
77
|
+
5. **Log** — record each blocked removal to telemetry with reason and pattern
|
|
78
|
+
|
|
79
|
+
Only items that survive the guard pass are eligible for compaction. The protocol is fail-closed: when in doubt, protect.
|
|
80
|
+
|
|
81
|
+
## Template Registry
|
|
82
|
+
|
|
83
|
+
Create `.opencode/flowdeck/protected-patterns.yaml`:
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
protected:
|
|
87
|
+
files:
|
|
88
|
+
- pattern: ".planning/STATE.md"
|
|
89
|
+
reason: "session state"
|
|
90
|
+
- pattern: ".planning/PLAN.md"
|
|
91
|
+
reason: "active plan"
|
|
92
|
+
- pattern: ".codebase/DECISIONS.jsonl"
|
|
93
|
+
reason: "decision ledger"
|
|
94
|
+
- pattern: ".codebase/FAILURES.json"
|
|
95
|
+
reason: "failure replay data"
|
|
96
|
+
- pattern: "AGENTS.md"
|
|
97
|
+
reason: "agent operating rules"
|
|
98
|
+
tools:
|
|
99
|
+
- name: "write"
|
|
100
|
+
while: "pending"
|
|
101
|
+
- name: "edit"
|
|
102
|
+
while: "pending"
|
|
103
|
+
- name: "bash"
|
|
104
|
+
while: "pending"
|
|
105
|
+
messages:
|
|
106
|
+
- type: "user"
|
|
107
|
+
count: 2
|
|
108
|
+
decisions:
|
|
109
|
+
- source: ".codebase/DECISIONS.jsonl"
|
|
110
|
+
count: 5
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Integration Notes
|
|
114
|
+
|
|
115
|
+
### `context-steward`
|
|
116
|
+
|
|
117
|
+
`context-steward` calls `context-guard` before every compaction pass:
|
|
118
|
+
|
|
119
|
+
- Pass the candidate removal list to the guard
|
|
120
|
+
- Receive the protected subset
|
|
121
|
+
- Remove only the non-protected remainder
|
|
122
|
+
- Write guard events to telemetry
|
|
123
|
+
|
|
124
|
+
Users do not call `context-guard` directly. It is a dependency of the compaction pipeline.
|
|
125
|
+
|
|
126
|
+
### Adding Project-Specific Patterns
|
|
127
|
+
|
|
128
|
+
1. Create `.opencode/flowdeck/protected-patterns.yaml`
|
|
129
|
+
2. Merge rules with the default registry (user patterns take precedence)
|
|
130
|
+
3. Re-run compaction to verify protection
|
|
131
|
+
|
|
132
|
+
Project patterns are appropriate for:
|
|
133
|
+
|
|
134
|
+
- Domain-specific safety files (e.g., `MIGRATIONS.md`, `SCHEMA.md`)
|
|
135
|
+
- Regulatory audit logs
|
|
136
|
+
- Long-running operation state files
|
|
137
|
+
|
|
138
|
+
Do not add transient build artifacts or cache files. Those are noise, not signal.
|
|
139
|
+
|
|
140
|
+
## Anti-Patterns
|
|
141
|
+
|
|
142
|
+
### Protecting Everything
|
|
143
|
+
|
|
144
|
+
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.
|
|
145
|
+
|
|
146
|
+
### Exact-Filename Protection
|
|
147
|
+
|
|
148
|
+
A pattern like `STATE.md` misses `.planning/STATE.md`. A pattern like `PLAN.md` misses phase-specific plans at `.planning/phases/phase-3/PLAN.md`. Use glob-style or prefix patterns so protection survives path changes.
|
|
149
|
+
|
|
150
|
+
### Leaving Temporary Files Protected
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
### Protecting Raw Tool Output
|
|
155
|
+
|
|
156
|
+
Large outputs (`git diff`, test logs, MCP responses) are usually not state. Summarize them and protect the summary, not the full output.
|
|
157
|
+
|
|
158
|
+
## Quick Reference
|
|
159
|
+
|
|
160
|
+
| Pattern Type | Example | Keep Condition |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| File | `.planning/STATE.md` | Always |
|
|
163
|
+
| File | `.codebase/DECISIONS.jsonl` | Always |
|
|
164
|
+
| Tool | `write` | While pending |
|
|
165
|
+
| Tool | `edit` | While pending |
|
|
166
|
+
| Message | User turn | Last 2 |
|
|
167
|
+
| Decision | `.codebase/DECISIONS.jsonl` | Last 5 entries |
|
|
168
|
+
|
|
169
|
+
## Related Skills
|
|
170
|
+
|
|
171
|
+
- [`context-load`](./context-load/SKILL.md) — what to load at session start
|
|
172
|
+
- [`context-budget`](./context-budget/SKILL.md) — when and why to compact
|