@henrychien/agent-compaction
v0.1.1
Published
Shared client-side conversation **flush + summary** compaction for the agent chat surfaces (TUI, Excel taskpane, web). Pure, browser-safe ESM — no gateway, no IO. Each surface supplies a `summarizeFn` that runs the two compaction turns (memory-flush, then
Readme
@henrychien/agent-compaction
Shared client-side conversation flush + summary compaction for the agent
chat surfaces (TUI, Excel taskpane, web). Pure, browser-safe ESM — no gateway,
no IO. Each surface supplies a summarizeFn that runs the two compaction turns
(memory-flush, then summary) on an isolated session.
Single source of truth for the flush/summary prompts and the
needsCompaction / compactHistory logic, so every surface behaves identically.
The Telegram bot keeps its own Python copy, kept prompt-aligned by a test.
API
FLUSH_PROMPT,SUMMARY_PROMPT,SUMMARY_PREFIX,SUMMARY_ACK— canonical prompt text.DEFAULT_COMPACTION_OPTS—{ tokenThreshold: 100000, messageThreshold: 40, keepRecent: 10 }.estimateTokens(messages)— crudecontent.length / 4estimate.needsCompaction(messages, opts?)— token- or message-count trigger.buildFlushMessages(messages, opts?)/buildCompactionMessages(messages, opts?)— build the flush / summary turn prompt.compactHistory(messages, summarizeFn, opts?)— returns[summary, ack, ...recent], preserving the original retained-tail objects (generic over the message type).
All functions accept the same opts ({ tokenThreshold, messageThreshold, keepRecent }); pass one object per compaction cycle.
Design + rollout: docs/design/completed/compaction-shared-module-impl-plan.md and
docs/design/completed/compaction-architecture-map.md in the AI-excel-addin repo.
