Context Assembly
Invariant Principles
- Tier 1 Never Truncates: Essential context survives any budget pressure
- Budget Before Assembly: Calculate budget FIRST, then select
- Purpose Drives Selection: Design ≠ implementation ≠ review context
- Recency Over Completeness: Recent feedback > historical context
- Summarize, Don't Truncate: Intelligent summarization preserves signal
- Integration Points are Tier 1: Interface contracts are essential
Inputs / Outputs
| Input |
Required |
Description |
purpose |
Yes |
design, implementation, review, handoff, subagent |
token_budget |
Yes |
Maximum tokens available |
source_context |
Yes |
Raw context to select from |
| Output |
Type |
Description |
context_package |
Structured |
Tiered context ready for injection |
truncation_report |
Inline |
What was excluded and why |
Context Tiers
Over budget: remove Tier 3 first, then Tier 2. Never remove Tier 1.
| Tier |
Budget |
Content |
Examples |
| 1: Essential |
40-60% |
Active instructions, user decisions, current artifact, interface contracts, blocking issues |
Task spec, APIs, unresolved feedback |
| 2: Supporting |
20-35% |
Recent learnings, patterns, prior feedback, success criteria |
Last 2-3 iterations, codebase patterns |
| 3: Reference |
10-20% |
Historical context, rejected alternatives, verbose docs |
Early iterations, full docs (summarize instead) |
Purpose-Specific Packages
| Purpose |
Tier 1 Focus |
Budget Split |
Use With |
| Design |
Requirements, decisions, constraints, integration points |
50/30/20 |
brainstorming, writing-plans |
| Implementation |
Task spec, acceptance criteria, interfaces, test expectations |
60/25/15 |
test-driven-development, executing-plans |
| Review |
Code diff, requirements traced, test results |
55/30/15 |
code-review, fact-checking |
| Handoff |
Current position, pending work, active decisions, blocking issues |
70/20/10 |
session boundaries, compaction |
| Subagent |
Task, constraints, expected output format |
65/25/10 |
dispatching-parallel-agents |
Token Budget
Estimation: tokens ≈ chars / 4 (conservative)
Available budget: context_window - system_prompt - response_reserve - tool_overhead
Example: 200000 - 8000 - 4000 - 2000 = 186000
Smart Truncation: Never blind head/tail. Preserve structure: keep intro (30%) + conclusion (20%), mark omitted middle.
Cross-Session Context
| Action |
Items |
| Persist |
User decisions, validated assumptions, glossary, blocking issues |
| Regenerate |
File contents, test results, code patterns (may have changed) |
| Discard |
Exploration paths, rejected alternatives, verbose logs |
Handoff format: Position → Pending work → Active decisions → Key learnings → Verification commands
Reasoning Schema
Self-Check
1---2name: assembling-context3description: Use when preparing context for subagents or managing token budgets. Triggers: "prepare context for", "assemble context", "what context does X need", "token budget", "context package", or automatically invoked by implementing-features Phase 3.5 (work packets) and Phase 4.2 (parallel subagents).4---5
6# Context Assembly
7
8<ROLE>
9Context Curator. Deliver precisely the right information at the right time. Too little causes failures. Too much burns tokens and buries signal. Every token must earn its place.
10</ROLE>
11
12## Invariant Principles
13
141. **Tier 1 Never Truncates**: Essential context survives any budget pressure
152. **Budget Before Assembly**: Calculate budget FIRST, then select
163. **Purpose Drives Selection**: Design ≠ implementation ≠ review context
174. **Recency Over Completeness**: Recent feedback > historical context
185. **Summarize, Don't Truncate**: Intelligent summarization preserves signal
196. **Integration Points are Tier 1**: Interface contracts are essential
20
21## Inputs / Outputs
22
23| Input | Required | Description |
24|-------|----------|-------------|
25| `purpose` | Yes | `design`, `implementation`, `review`, `handoff`, `subagent` |
26| `token_budget` | Yes | Maximum tokens available |
27| `source_context` | Yes | Raw context to select from |
28
29| Output | Type | Description |
30|--------|------|-------------|
31| `context_package` | Structured | Tiered context ready for injection |
32| `truncation_report` | Inline | What was excluded and why |
33
34---
35
36## Context Tiers
37
38<CRITICAL>Over budget: remove Tier 3 first, then Tier 2. Never remove Tier 1.</CRITICAL>
39
40| Tier | Budget | Content | Examples |
41|------|--------|---------|----------|
42| **1: Essential** | 40-60% | Active instructions, user decisions, current artifact, interface contracts, blocking issues | Task spec, APIs, unresolved feedback |
43| **2: Supporting** | 20-35% | Recent learnings, patterns, prior feedback, success criteria | Last 2-3 iterations, codebase patterns |
44| **3: Reference** | 10-20% | Historical context, rejected alternatives, verbose docs | Early iterations, full docs (summarize instead) |
45
46---
47
48## Purpose-Specific Packages
49
50| Purpose | Tier 1 Focus | Budget Split | Use With |
51|---------|--------------|--------------|----------|
52| **Design** | Requirements, decisions, constraints, integration points | 50/30/20 | brainstorming, writing-plans |
53| **Implementation** | Task spec, acceptance criteria, interfaces, test expectations | 60/25/15 | test-driven-development, executing-plans |
54| **Review** | Code diff, requirements traced, test results | 55/30/15 | code-review, fact-checking |
55| **Handoff** | Current position, pending work, active decisions, blocking issues | 70/20/10 | session boundaries, compaction |
56| **Subagent** | Task, constraints, expected output format | 65/25/10 | dispatching-parallel-agents |
57
58---
59
60## Token Budget
61
62**Estimation:** `tokens ≈ chars / 4` (conservative)
63
64**Available budget:** `context_window - system_prompt - response_reserve - tool_overhead`
65Example: `200000 - 8000 - 4000 - 2000 = 186000`
66
67**Smart Truncation:** Never blind `head`/`tail`. Preserve structure: keep intro (30%) + conclusion (20%), mark omitted middle.
68
69---
70
71## Cross-Session Context
72
73| Action | Items |
74|--------|-------|
75| **Persist** | User decisions, validated assumptions, glossary, blocking issues |
76| **Regenerate** | File contents, test results, code patterns (may have changed) |
77| **Discard** | Exploration paths, rejected alternatives, verbose logs |
78
79**Handoff format:** Position → Pending work → Active decisions → Key learnings → Verification commands
80
81---
82
83## Reasoning Schema
84
85<analysis>
86Before assembling: PURPOSE? TOKEN BUDGET? TIER 1 for this purpose? RECIPIENT?
87</analysis>
88
89<reflection>
90After assembling: Tier 1 fits? Essential excluded? Room for Tier 2? Truncation report accurate?
91</reflection>
92
93---
94
95<FORBIDDEN>
96- Assembling without calculating budget first
97- Blind truncation (`head`, `tail -n`, arbitrary limits)
98- Truncating Tier 1 to fit budget
99- Same package for different purposes
100- Omitting integration points
101- Including exploration paths in handoff
102- Persisting raw command output across sessions
103</FORBIDDEN>
104
105## Self-Check
106
107- [ ] Calculated token budget explicitly
108- [ ] Identified Tier 1 for this purpose
109- [ ] Tier 1 fits within budget
110- [ ] Smart truncation applied (not blind)
111- [ ] Integration points included
112- [ ] Truncation report created
113
114<FINAL_EMPHASIS>
115Context assembly is invisible infrastructure. Calculate budget. Prioritize by tier. Truncate intelligently. Every token earns its place.
116</FINAL_EMPHASIS>