opencodekit 0.15.19 → 0.15.20
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/dist/index.js +1 -1
- package/dist/template/.opencode/memory/observations/2026-01-30-discovery-context-management-research-critical-gap.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-decision-copilot-auth-plugin-updated-with-baseurl.md +63 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-auth-comparison-finding.md +61 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-reasoning-architecture-.md +66 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-warning-copilot-claude-v1-endpoint-returns-404-c.md +48 -0
- package/dist/template/.opencode/memory/research/context-management-analysis.md +685 -0
- package/dist/template/.opencode/opencode.json +52 -156
- package/dist/template/.opencode/package.json +1 -1
- package/dist/template/.opencode/plugins/copilot-auth.ts +289 -24
- package/dist/template/.opencode/plugins/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +181 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/get-response-metadata.ts +15 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-api-types.ts +72 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-chat-language-model.ts +823 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-chat-options.ts +30 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +48 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-prepare-tools.ts +92 -0
- package/dist/template/.opencode/plugins/sdk/copilot/copilot-provider.ts +94 -0
- package/dist/template/.opencode/plugins/sdk/copilot/index.ts +5 -0
- package/dist/template/.opencode/plugins/sdk/copilot/openai-compatible-error.ts +30 -0
- package/package.json +1 -1
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
# Context Management Research Analysis
|
|
2
|
+
|
|
3
|
+
## How Contexts Fail & How to Fix Them - Adaptation for OpenCodeKit
|
|
4
|
+
|
|
5
|
+
**Source**: https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html
|
|
6
|
+
**Follow-up**: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
|
|
7
|
+
**Analysis Date**: 2026-01-30
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Executive Summary
|
|
12
|
+
|
|
13
|
+
The research reveals that **longer contexts do NOT generate better responses**. Context windows beyond 100k tokens cause models to favor repeating past actions over synthesizing novel plans. OpenCodeKit has strong foundations but significant gaps in tool management, context isolation, and structured context assembly.
|
|
14
|
+
|
|
15
|
+
**Verdict**: OpenCodeKit is at **70% maturity** on context management. Critical gaps exist in tool loadout, context offloading, and poisoning prevention.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## The Four Context Failure Modes
|
|
20
|
+
|
|
21
|
+
### 1. Context Poisoning (CRITICAL GAP)
|
|
22
|
+
|
|
23
|
+
**Definition**: Hallucinations or errors enter context and are repeatedly referenced, compounding over time.
|
|
24
|
+
|
|
25
|
+
**Research Evidence**:
|
|
26
|
+
|
|
27
|
+
- Gemini 2.5 playing Pokémon: goals section poisoned with misinformation about game state
|
|
28
|
+
- Agent developed nonsensical strategies pursuing impossible goals
|
|
29
|
+
- "Can take a very long time to undo"
|
|
30
|
+
|
|
31
|
+
**OpenCodeKit Status**: ❌ **NO PROTECTION**
|
|
32
|
+
|
|
33
|
+
- No validation layer before tool outputs enter context
|
|
34
|
+
- No mechanism to detect/correct hallucinations
|
|
35
|
+
- Subagent reports trusted without verification
|
|
36
|
+
- Tool outputs (grep, read, webfetch) enter context raw
|
|
37
|
+
|
|
38
|
+
**Impact**: HIGH - Every tool call risks poisoning
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### 2. Context Distraction (PARTIALLY ADDRESSED)
|
|
43
|
+
|
|
44
|
+
**Definition**: Context grows so long that model over-focuses on context, neglecting training knowledge.
|
|
45
|
+
|
|
46
|
+
**Research Evidence**:
|
|
47
|
+
|
|
48
|
+
- Gemini 2.5 Pro: beyond 100k tokens, agent repeats actions from history vs synthesizing novel plans
|
|
49
|
+
- Llama 3.1 405b: correctness falls around 32k tokens
|
|
50
|
+
- Smaller models fail earlier
|
|
51
|
+
|
|
52
|
+
**OpenCodeKit Status**: ⚠️ **PARTIAL - Good thresholds, no enforcement**
|
|
53
|
+
|
|
54
|
+
- ✅ Has thresholds: 70%, 85%, 95%
|
|
55
|
+
- ✅ Session management skill recommends <150k tokens
|
|
56
|
+
- ❌ No hard enforcement of thresholds
|
|
57
|
+
- ❌ No automatic summarization at thresholds
|
|
58
|
+
- ❌ No model-specific limits (Claude vs Gemini vs GPT)
|
|
59
|
+
|
|
60
|
+
**Impact**: MEDIUM - Guidelines exist but not enforced
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 3. Context Confusion (CRITICAL GAP)
|
|
65
|
+
|
|
66
|
+
**Definition**: Superfluous content in context influences responses negatively.
|
|
67
|
+
|
|
68
|
+
**Research Evidence**:
|
|
69
|
+
|
|
70
|
+
- Berkeley Function-Calling Leaderboard: ALL models perform worse with >1 tool
|
|
71
|
+
- Llama 3.1 8b: fails with 46 tools, succeeds with 19 tools
|
|
72
|
+
- DeepSeek-v3: critical threshold at 30 tools, guaranteed failure beyond 100
|
|
73
|
+
- Tool RAG improves accuracy 3x
|
|
74
|
+
|
|
75
|
+
**OpenCodeKit Status**: ❌ **NO TOOL LOADOUT SYSTEM**
|
|
76
|
+
|
|
77
|
+
- All 40+ tools loaded into context simultaneously
|
|
78
|
+
- No dynamic tool selection based on task
|
|
79
|
+
- No tool RAG/semantic selection
|
|
80
|
+
- Skills add MORE tools to context
|
|
81
|
+
- MCP servers add even more tools
|
|
82
|
+
|
|
83
|
+
**Impact**: CRITICAL - 40+ tools in context violates research findings
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 4. Context Clash (MODERATE GAP)
|
|
88
|
+
|
|
89
|
+
**Definition**: New information conflicts with existing context, derailing reasoning.
|
|
90
|
+
|
|
91
|
+
**Research Evidence**:
|
|
92
|
+
|
|
93
|
+
- Microsoft/Salesforce study: sharded prompts yield 39% worse results
|
|
94
|
+
- o3 score dropped from 98.1 to 64.1 with multi-turn assembly
|
|
95
|
+
- Models make assumptions early, get lost and don't recover
|
|
96
|
+
|
|
97
|
+
**OpenCodeKit Status**: ⚠️ **PARTIAL - Subagents help, no clash detection**
|
|
98
|
+
|
|
99
|
+
- ✅ Subagents provide some isolation
|
|
100
|
+
- ✅ Fresh subagent per task reduces accumulation
|
|
101
|
+
- ❌ No clash detection between memory + session + tool outputs
|
|
102
|
+
- ❌ No validation that assembled context is coherent
|
|
103
|
+
- ❌ Multi-turn conversations accumulate conflicting info
|
|
104
|
+
|
|
105
|
+
**Impact**: MEDIUM - Architecture helps but no active prevention
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Six Solutions from Research
|
|
110
|
+
|
|
111
|
+
### 1. RAG (Retrieval-Augmented Generation)
|
|
112
|
+
|
|
113
|
+
**Research**: Selectively add relevant information vs dumping everything
|
|
114
|
+
|
|
115
|
+
**OpenCodeKit Status**: ✅ **IMPLEMENTED**
|
|
116
|
+
|
|
117
|
+
- memory-search for relevant past context
|
|
118
|
+
- context7 for library docs
|
|
119
|
+
- exa for web search
|
|
120
|
+
- grepsearch for code patterns
|
|
121
|
+
|
|
122
|
+
**Gap**: Not applied to tool selection
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### 2. Tool Loadout (CRITICAL MISSING)
|
|
127
|
+
|
|
128
|
+
**Research**: Select only relevant tools (<30 for best performance)
|
|
129
|
+
|
|
130
|
+
**OpenCodeKit Status**: ❌ **NOT IMPLEMENTED**
|
|
131
|
+
|
|
132
|
+
**What We Need**:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Tool RAG - semantic selection
|
|
136
|
+
const relevantTools = await toolRAG({
|
|
137
|
+
task: "Add authentication",
|
|
138
|
+
availableTools: allTools,
|
|
139
|
+
maxTools: 25, // Research says <30
|
|
140
|
+
selectionMethod: "semantic-similarity",
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Result: Only auth-related tools loaded
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Implementation Options**:
|
|
147
|
+
|
|
148
|
+
1. **Static Loadouts**: Pre-defined tool sets per command
|
|
149
|
+
- `/design` → UI/UX tools only
|
|
150
|
+
- `/fix` → debugging tools only
|
|
151
|
+
- `/implement` → code editing tools only
|
|
152
|
+
|
|
153
|
+
2. **Dynamic RAG**: Vector search tool descriptions
|
|
154
|
+
- Store tool descriptions in vector DB
|
|
155
|
+
- Query with user task
|
|
156
|
+
- Return top-K relevant tools
|
|
157
|
+
|
|
158
|
+
3. **Hybrid**: Static base + dynamic additions
|
|
159
|
+
- Core tools always loaded (read, edit, bash)
|
|
160
|
+
- Specialized tools selected dynamically
|
|
161
|
+
|
|
162
|
+
**Priority**: CRITICAL - Immediate impact on performance
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### 3. Context Quarantine (PARTIALLY IMPLEMENTED)
|
|
167
|
+
|
|
168
|
+
**Research**: Isolate contexts in dedicated threads
|
|
169
|
+
|
|
170
|
+
**OpenCodeKit Status**: ⚠️ **PARTIAL - Subagents exist, isolation incomplete**
|
|
171
|
+
|
|
172
|
+
**Current**:
|
|
173
|
+
|
|
174
|
+
- Subagents spawned for parallel tasks
|
|
175
|
+
- Fresh context per subagent
|
|
176
|
+
- Mailbox coordination
|
|
177
|
+
|
|
178
|
+
**Gaps**:
|
|
179
|
+
|
|
180
|
+
- Subagents can still access full tool set
|
|
181
|
+
- No strict context boundaries
|
|
182
|
+
- Leader context accumulates subagent reports
|
|
183
|
+
- No "air gap" between contexts
|
|
184
|
+
|
|
185
|
+
**What We Need**:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// True quarantine - subagent gets ONLY:
|
|
189
|
+
// - Delegation packet
|
|
190
|
+
// - Assigned files
|
|
191
|
+
// - Minimal tool set (3-5 tools)
|
|
192
|
+
// - NO access to leader's full context
|
|
193
|
+
|
|
194
|
+
const quarantinedSubagent = await Task({
|
|
195
|
+
subagent_type: "general",
|
|
196
|
+
contextIsolation: "strict", // NEW
|
|
197
|
+
allowedTools: ["read", "edit", "bash"], // Limited loadout
|
|
198
|
+
maxTokens: 50000, // Hard limit
|
|
199
|
+
delegationOnly: true, // Can only see delegation packet
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### 4. Context Pruning (IMPLEMENTED BUT MANUAL)
|
|
206
|
+
|
|
207
|
+
**Research**: Remove irrelevant information (Provence achieved 95% reduction)
|
|
208
|
+
|
|
209
|
+
**OpenCodeKit Status**: ⚠️ **PARTIAL - Tools exist, not automated**
|
|
210
|
+
|
|
211
|
+
**Current**:
|
|
212
|
+
|
|
213
|
+
- `discard` tool for removing outputs
|
|
214
|
+
- `extract` tool for distilling knowledge
|
|
215
|
+
- Session thresholds (70%, 85%, 95%)
|
|
216
|
+
|
|
217
|
+
**Gaps**:
|
|
218
|
+
|
|
219
|
+
- Manual - agent must decide what to prune
|
|
220
|
+
- No automated pruning at thresholds
|
|
221
|
+
- No Provence-like intelligent pruning
|
|
222
|
+
- No structured context to prune from
|
|
223
|
+
|
|
224
|
+
**What We Need**:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
// Automated pruning at 85% threshold
|
|
228
|
+
if (contextUsage > 0.85) {
|
|
229
|
+
// 1. Identify low-value content
|
|
230
|
+
const pruneable = await identifyPrunableContent({
|
|
231
|
+
context: currentContext,
|
|
232
|
+
criteria: [
|
|
233
|
+
"completed task outputs",
|
|
234
|
+
"superseded tool results",
|
|
235
|
+
"intermediate calculations",
|
|
236
|
+
"verbose logs"
|
|
237
|
+
]
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// 2. Extract key findings before discarding
|
|
241
|
+
await extract({ ids: pruneable.ids, distillation: [...] });
|
|
242
|
+
|
|
243
|
+
// 3. Auto-discard
|
|
244
|
+
await discard({ ids: pruneable.ids, reason: "threshold_auto_prune" });
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### 5. Context Summarization (NOT IMPLEMENTED)
|
|
251
|
+
|
|
252
|
+
**Research**: Boil down accrued context into condensed summary
|
|
253
|
+
|
|
254
|
+
**OpenCodeKit Status**: ❌ **NOT IMPLEMENTED**
|
|
255
|
+
|
|
256
|
+
**Current**:
|
|
257
|
+
|
|
258
|
+
- `summarize_session` exists but not used in workflow
|
|
259
|
+
- No automatic summarization at thresholds
|
|
260
|
+
|
|
261
|
+
**What We Need**:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// At 100k tokens, auto-summarize
|
|
265
|
+
const summary = await summarizeContext({
|
|
266
|
+
context: currentContext,
|
|
267
|
+
preserve: ["active_task_spec", "uncommitted_changes", "critical_decisions"],
|
|
268
|
+
compress: ["tool_outputs", "completed_subtasks", "research_findings"],
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Replace bloated context with summary + preserved essentials
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### 6. Context Offloading (PARTIALLY IMPLEMENTED)
|
|
277
|
+
|
|
278
|
+
**Research**: Store information outside LLM context via tools
|
|
279
|
+
|
|
280
|
+
**OpenCodeKit Status**: ⚠️ **PARTIAL - Memory system exists, no scratchpad**
|
|
281
|
+
|
|
282
|
+
**Current**:
|
|
283
|
+
|
|
284
|
+
- Memory files for persistent storage
|
|
285
|
+
- Beads for task tracking
|
|
286
|
+
- Observations for structured findings
|
|
287
|
+
|
|
288
|
+
**Gaps**:
|
|
289
|
+
|
|
290
|
+
- No "think tool" / scratchpad pattern
|
|
291
|
+
- No structured context assembly
|
|
292
|
+
- Everything compiled into single context string
|
|
293
|
+
|
|
294
|
+
**What We Need - Scratchpad Tool**:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// Anthropic's "think tool" pattern
|
|
298
|
+
const scratchpad = await tool({
|
|
299
|
+
name: "scratchpad_write",
|
|
300
|
+
section: "reasoning", // reasoning, notes, progress, concerns
|
|
301
|
+
content: "The bug appears to be in the auth middleware...",
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// Later retrieval
|
|
305
|
+
const notes = await scratchpad_read({ section: "reasoning" });
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**What We Need - Structured Context**:
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
// Structured context assembly
|
|
312
|
+
const contextAssembly = {
|
|
313
|
+
instructions: AGENTS_MD, // Always present
|
|
314
|
+
active_task: beadSpec, // Current focus
|
|
315
|
+
scratchpad: {...}, // Working notes
|
|
316
|
+
memory: {...}, // Relevant past context
|
|
317
|
+
tools: [...], // Current loadout
|
|
318
|
+
history: [...], // Recent actions (pruned)
|
|
319
|
+
// Compile to string only at LLM call time
|
|
320
|
+
};
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Brutal Assessment by Component
|
|
326
|
+
|
|
327
|
+
### AGENTS.md (The Foundation)
|
|
328
|
+
|
|
329
|
+
**Score**: 7/10
|
|
330
|
+
|
|
331
|
+
**Strengths**:
|
|
332
|
+
|
|
333
|
+
- Clear delegation rules
|
|
334
|
+
- LSP verification chain
|
|
335
|
+
- Memory checkpoints
|
|
336
|
+
- Anti-hallucination protocols
|
|
337
|
+
|
|
338
|
+
**Weaknesses**:
|
|
339
|
+
|
|
340
|
+
- No tool loadout guidance
|
|
341
|
+
- No context size limits per model
|
|
342
|
+
- No scratchpad/think tool mention
|
|
343
|
+
- No context clash detection
|
|
344
|
+
|
|
345
|
+
**Recommendations**:
|
|
346
|
+
|
|
347
|
+
1. Add "Tool Loadout" section - limit to <30 tools
|
|
348
|
+
2. Add "Context Assembly" section - structured context
|
|
349
|
+
3. Add "Scratchpad" pattern for working notes
|
|
350
|
+
4. Add model-specific context limits
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
### Session Management Skill
|
|
355
|
+
|
|
356
|
+
**Score**: 6/10
|
|
357
|
+
|
|
358
|
+
**Strengths**:
|
|
359
|
+
|
|
360
|
+
- Thresholds defined (70%, 85%, 95%)
|
|
361
|
+
- Pruning strategy documented
|
|
362
|
+
- Session restart guidance
|
|
363
|
+
|
|
364
|
+
**Weaknesses**:
|
|
365
|
+
|
|
366
|
+
- No automated actions at thresholds
|
|
367
|
+
- No summarization workflow
|
|
368
|
+
- No model-specific guidance
|
|
369
|
+
- Thresholds are suggestions, not enforced
|
|
370
|
+
|
|
371
|
+
**Recommendations**:
|
|
372
|
+
|
|
373
|
+
1. Auto-trigger extract+discard at 85%
|
|
374
|
+
2. Auto-summarize at 100k tokens
|
|
375
|
+
3. Hard stop at 150k tokens
|
|
376
|
+
4. Model-specific limits (Claude: 100k, Gemini: 150k, GPT: 80k)
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
### Memory System Skill
|
|
381
|
+
|
|
382
|
+
**Score**: 8/10
|
|
383
|
+
|
|
384
|
+
**Strengths**:
|
|
385
|
+
|
|
386
|
+
- Structured storage
|
|
387
|
+
- Search capability
|
|
388
|
+
- Observation pattern
|
|
389
|
+
- Cross-session persistence
|
|
390
|
+
|
|
391
|
+
**Weaknesses**:
|
|
392
|
+
|
|
393
|
+
- No RAG for memory retrieval (keyword only)
|
|
394
|
+
- No automatic memory updates
|
|
395
|
+
- No memory pruning/aging
|
|
396
|
+
|
|
397
|
+
**Recommendations**:
|
|
398
|
+
|
|
399
|
+
1. Add semantic search for memories
|
|
400
|
+
2. Auto-update memory at task completion
|
|
401
|
+
3. Add memory relevance scoring
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
### Swarm Coordination Skill
|
|
406
|
+
|
|
407
|
+
**Score**: 8/10
|
|
408
|
+
|
|
409
|
+
**Strengths**:
|
|
410
|
+
|
|
411
|
+
- Fresh subagent per task (quarantine)
|
|
412
|
+
- Delegation packets
|
|
413
|
+
- Progress tracking
|
|
414
|
+
- Mailbox coordination
|
|
415
|
+
|
|
416
|
+
**Weaknesses**:
|
|
417
|
+
|
|
418
|
+
- Subagents still get full tool set
|
|
419
|
+
- No strict context isolation
|
|
420
|
+
- Leader accumulates all subagent outputs
|
|
421
|
+
|
|
422
|
+
**Recommendations**:
|
|
423
|
+
|
|
424
|
+
1. Tool loadout per subagent type
|
|
425
|
+
2. Strict context boundaries
|
|
426
|
+
3. Synthesized reports vs raw outputs
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### Subagent-Driven Development Skill
|
|
431
|
+
|
|
432
|
+
**Score**: 7/10
|
|
433
|
+
|
|
434
|
+
**Strengths**:
|
|
435
|
+
|
|
436
|
+
- Fresh context per task
|
|
437
|
+
- Review between tasks
|
|
438
|
+
- No context pollution
|
|
439
|
+
|
|
440
|
+
**Weaknesses**:
|
|
441
|
+
|
|
442
|
+
- No mention of tool limits
|
|
443
|
+
- No context size monitoring
|
|
444
|
+
- Review adds more context
|
|
445
|
+
|
|
446
|
+
**Recommendations**:
|
|
447
|
+
|
|
448
|
+
1. Limit subagent tools to 5-10
|
|
449
|
+
2. Monitor subagent context size
|
|
450
|
+
3. Summarize review findings
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## Critical Adaptations Needed
|
|
455
|
+
|
|
456
|
+
### 1. Tool Loadout System (P0 - Critical)
|
|
457
|
+
|
|
458
|
+
**Problem**: 40+ tools in context violates research (failures >30 tools)
|
|
459
|
+
|
|
460
|
+
**Solution**:
|
|
461
|
+
|
|
462
|
+
```yaml
|
|
463
|
+
# .opencode/config/tool-loadouts.yaml
|
|
464
|
+
default:
|
|
465
|
+
- read
|
|
466
|
+
- edit
|
|
467
|
+
- bash
|
|
468
|
+
- grep
|
|
469
|
+
- memory-read
|
|
470
|
+
|
|
471
|
+
design:
|
|
472
|
+
extends: default
|
|
473
|
+
- skill_mcp # Figma, Stitch
|
|
474
|
+
- vision_agent
|
|
475
|
+
|
|
476
|
+
debug:
|
|
477
|
+
extends: default
|
|
478
|
+
- lsp
|
|
479
|
+
- systematic_debugging_skill
|
|
480
|
+
|
|
481
|
+
research:
|
|
482
|
+
extends: default
|
|
483
|
+
- websearch
|
|
484
|
+
- codesearch
|
|
485
|
+
- context7
|
|
486
|
+
- grepsearch
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Implementation**:
|
|
490
|
+
|
|
491
|
+
1. Create tool categorization
|
|
492
|
+
2. Map commands to loadouts
|
|
493
|
+
3. Add dynamic tool RAG for edge cases
|
|
494
|
+
4. Measure impact on accuracy
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
### 2. Structured Context Assembly (P0 - Critical)
|
|
499
|
+
|
|
500
|
+
**Problem**: Context is unstructured string, hard to prune/summarize
|
|
501
|
+
|
|
502
|
+
**Solution**:
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
// Context sections with priorities
|
|
506
|
+
interface ContextAssembly {
|
|
507
|
+
system: Section<"critical">; // AGENTS.md - never pruned
|
|
508
|
+
instructions: Section<"critical">; // Task spec - never pruned
|
|
509
|
+
scratchpad: Section<"high">; // Working notes - summarized
|
|
510
|
+
memory: Section<"high">; // Relevant past - RAG selected
|
|
511
|
+
tools: Section<"medium">; // Tool definitions - loadout
|
|
512
|
+
history: Section<"low">; // Action history - aggressively pruned
|
|
513
|
+
working: Section<"low">; // Current tool outputs - pruned after use
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**Implementation**:
|
|
518
|
+
|
|
519
|
+
1. Define context sections
|
|
520
|
+
2. Assign priority levels
|
|
521
|
+
3. Implement section-aware pruning
|
|
522
|
+
4. Compile to string at LLM call time
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
526
|
+
### 3. Scratchpad / Think Tool (P1 - High)
|
|
527
|
+
|
|
528
|
+
**Problem**: No place for working notes outside main context
|
|
529
|
+
|
|
530
|
+
**Solution**:
|
|
531
|
+
|
|
532
|
+
```typescript
|
|
533
|
+
// scratchpad tool
|
|
534
|
+
interface Scratchpad {
|
|
535
|
+
reasoning: string[]; // Current thinking
|
|
536
|
+
concerns: string[]; // Issues to watch
|
|
537
|
+
progress: string[]; // Completed steps
|
|
538
|
+
notes: string[]; // General notes
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Usage
|
|
542
|
+
scratchpad_write({
|
|
543
|
+
section: "reasoning",
|
|
544
|
+
content: "The auth flow has 3 steps: 1) validate token...",
|
|
545
|
+
});
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
**Benefits**:
|
|
549
|
+
|
|
550
|
+
- Offload working memory from context
|
|
551
|
+
- Structured notes vs scattered thoughts
|
|
552
|
+
- Survives pruning
|
|
553
|
+
|
|
554
|
+
---
|
|
555
|
+
|
|
556
|
+
### 4. Automated Context Maintenance (P1 - High)
|
|
557
|
+
|
|
558
|
+
**Problem**: Manual pruning is inconsistent
|
|
559
|
+
|
|
560
|
+
**Solution**:
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
// Auto-maintenance at thresholds
|
|
564
|
+
contextMaintenance: {
|
|
565
|
+
at_70_percent: "warn_and_consolidate",
|
|
566
|
+
at_85_percent: "extract_and_prune",
|
|
567
|
+
at_100k_tokens: "summarize_history",
|
|
568
|
+
at_95_percent: "critical_prune_or_restart"
|
|
569
|
+
}
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
**Actions**:
|
|
573
|
+
|
|
574
|
+
1. 70%: Warn, suggest consolidation
|
|
575
|
+
2. 85%: Auto-extract key findings, prune completed work
|
|
576
|
+
3. 100k: Summarize history section
|
|
577
|
+
4. 95%: Aggressive prune or force restart
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
### 5. Context Poisoning Detection (P2 - Medium)
|
|
582
|
+
|
|
583
|
+
**Problem**: No validation before tool outputs enter context
|
|
584
|
+
|
|
585
|
+
**Solution**:
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
// Validation layer
|
|
589
|
+
interface ContextValidator {
|
|
590
|
+
// Check for hallucinations in tool outputs
|
|
591
|
+
validateToolOutput(output: ToolOutput): ValidationResult;
|
|
592
|
+
|
|
593
|
+
// Detect contradictions in context
|
|
594
|
+
detectClashes(context: ContextAssembly): ClashReport;
|
|
595
|
+
|
|
596
|
+
// Verify subagent reports
|
|
597
|
+
verifySubagentReport(report: SubagentReport): VerificationResult;
|
|
598
|
+
}
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
**Implementation**:
|
|
602
|
+
|
|
603
|
+
1. Flag suspicious tool outputs
|
|
604
|
+
2. Detect contradictions between sources
|
|
605
|
+
3. Verify subagent claims before accepting
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## What OpenCodeKit Does Well
|
|
610
|
+
|
|
611
|
+
1. **Session Management**: Thresholds are research-aligned (70%, 85%, 95%)
|
|
612
|
+
2. **Subagent Pattern**: Fresh context per task reduces distraction
|
|
613
|
+
3. **Memory System**: Good context offloading to persistent storage
|
|
614
|
+
4. **Pruning Tools**: discard/extract provide foundation
|
|
615
|
+
5. **Parallel Execution**: Reduces per-agent context accumulation
|
|
616
|
+
6. **Swarm Coordination**: Delegation packets limit context per worker
|
|
617
|
+
|
|
618
|
+
---
|
|
619
|
+
|
|
620
|
+
## What OpenCodeKit Gets Wrong
|
|
621
|
+
|
|
622
|
+
1. **Tool Overload**: 40+ tools in context is 33% over research limit
|
|
623
|
+
2. **Manual Pruning**: No automated context maintenance
|
|
624
|
+
3. **No Scratchpad**: Working notes pollute main context
|
|
625
|
+
4. **Unstructured Context**: Can't intelligently prune/summarize
|
|
626
|
+
5. **No Poisoning Detection**: Tool outputs enter context unchecked
|
|
627
|
+
6. **One-Size-Fits-All**: No model-specific context limits
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## Implementation Roadmap
|
|
632
|
+
|
|
633
|
+
### Phase 1: Tool Loadout (Immediate - 1 week)
|
|
634
|
+
|
|
635
|
+
- [ ] Categorize all tools by function
|
|
636
|
+
- [ ] Create static loadouts per command
|
|
637
|
+
- [ ] Implement loadout selection
|
|
638
|
+
- [ ] Measure accuracy improvement
|
|
639
|
+
|
|
640
|
+
### Phase 2: Structured Context (2 weeks)
|
|
641
|
+
|
|
642
|
+
- [ ] Define context sections
|
|
643
|
+
- [ ] Implement section-aware pruning
|
|
644
|
+
- [ ] Add scratchpad tool
|
|
645
|
+
- [ ] Test with long sessions
|
|
646
|
+
|
|
647
|
+
### Phase 3: Automation (2 weeks)
|
|
648
|
+
|
|
649
|
+
- [ ] Auto-extract at 85%
|
|
650
|
+
- [ ] Auto-summarize at 100k
|
|
651
|
+
- [ ] Model-specific limits
|
|
652
|
+
- [ ] Hard stop at 150k
|
|
653
|
+
|
|
654
|
+
### Phase 4: Validation (3 weeks)
|
|
655
|
+
|
|
656
|
+
- [ ] Context poisoning detection
|
|
657
|
+
- [ ] Clash detection
|
|
658
|
+
- [ ] Subagent verification
|
|
659
|
+
- [ ] Quality metrics
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
## Success Metrics
|
|
664
|
+
|
|
665
|
+
| Metric | Current | Target |
|
|
666
|
+
| ------------------------ | ------- | --------- |
|
|
667
|
+
| Tools in context | 40+ | <25 |
|
|
668
|
+
| Avg session tokens | ~200k | <100k |
|
|
669
|
+
| Manual pruning rate | 30% | 80% auto |
|
|
670
|
+
| Context restarts | Rare | Proactive |
|
|
671
|
+
| Task completion accuracy | Unknown | +20% |
|
|
672
|
+
|
|
673
|
+
---
|
|
674
|
+
|
|
675
|
+
## Conclusion
|
|
676
|
+
|
|
677
|
+
OpenCodeKit has solid foundations but **critical gaps in tool management**. The research is clear: >30 tools causes failures. We have 40+.
|
|
678
|
+
|
|
679
|
+
**Immediate action**: Implement tool loadout system. This alone should improve accuracy 20-40% based on research findings.
|
|
680
|
+
|
|
681
|
+
**Secondary priority**: Structured context assembly + scratchpad. Enables intelligent pruning and offloading.
|
|
682
|
+
|
|
683
|
+
The research validates our session management approach but shows we're not aggressive enough with enforcement. The 70/85/95 thresholds are correct, but we need automated actions at each level, not just warnings.
|
|
684
|
+
|
|
685
|
+
**Bottom line**: We're 70% there. Tool loadout is the missing 30% that unlocks the other 70%.
|