Summary
Add a deterministic, budget-aware context compiler that selects the highest-value context before serialization instead of resolving everything and truncating the final string.
Problem
Current token limiting uses a lightweight character estimate and slices final output. It can cut through sections, omit high-value context after lower-value content, duplicate the same element across focus/viewport/history, and spend time resolving sources that cannot fit.
Proposed API
const compiled = await ctx.compileContext({
budget: { maxTokens: 800, count: modelTokenCounter },
priority: ['explicit-selection', 'focus', 'selected-sources', 'viewport', 'history'],
dedupe: 'askable-id',
sources: 'all',
});
compiled.text;
compiled.packet;
compiled.report.included;
compiled.report.omitted;
compiled.report.estimatedTokens;
Acceptance criteria
Summary
Add a deterministic, budget-aware context compiler that selects the highest-value context before serialization instead of resolving everything and truncating the final string.
Problem
Current token limiting uses a lightweight character estimate and slices final output. It can cut through sections, omit high-value context after lower-value content, duplicate the same element across focus/viewport/history, and spend time resolving sources that cannot fit.
Proposed API
Acceptance criteria