@moxxy/compactor-summarize is the default compactor. It watches the session's estimated token use; once usage crosses a threshold ratio of the active model's context window, it replaces a prefix of old turns with a single summary event — freeing space without losing the gist.
Install
sh
pnpm add @moxxy/compactor-summarizeUse
ts
import { summarizeCompactorPlugin } from '@moxxy/compactor-summarize';
session.pluginHost.registerStatic(summarizeCompactorPlugin);Or build with custom options:
ts
import { createSummarizeCompactor } from '@moxxy/compactor-summarize';
const compactor = createSummarizeCompactor({
thresholdRatio: 0.75, // compact when > 75% of the context window
keepRecentTurns: 3, // always keep the last 3 turns verbatim
summary: async (text) => await myLlmSummarize(text), // optional async summarizer
});How it works
shouldCompact(log, budget)returns true onceestimatedTokens > thresholdRatio * contextWindow.compact(events)skips anything already covered by a previousCompactionEvent.replacedRange(high-water mark), drops the lastkeepRecentTurnsturns from consideration, summarizes the remainder, and emits acompactionevent covering the replaced range.- The session projects that event in place of the original turns next time the message history is folded.
This makes compaction idempotent — re-running it never double-summarizes.
Exports
summarizeCompactorPlugin,createSummarizeCompactorSummarizeOptions
Default summary
If you don't pass a summary function, the bundled fallback truncates to the first 5 lines + a "(N more lines)" marker. Replace it for any real workload — a one-line LLM summary is dramatically better.
