Skip to content

feat: session compaction#21

Merged
davexpro merged 11 commits into
mainfrom
feat/session-compaction
Mar 5, 2026
Merged

feat: session compaction#21
davexpro merged 11 commits into
mainfrom
feat/session-compaction

Conversation

@davexpro

@davexpro davexpro commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

davexpro and others added 8 commits March 2, 2026 22:33
Adds a heuristic token estimator (byte-length / 4) used by session
compaction to detect when token usage approaches the context window limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…action

Add session compaction support: Compact() replaces old messages with a
summary while keeping the most recent N messages. History() now prepends
the active summary message when present, and Clear() resets all
compaction state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add compact record type to the JSONL format so that compaction summary
and version survive across Save/Load cycles. On rewrite, a "compact"
record is emitted between the metadata line and the kept messages. On
Load, encountering a compact record resets the message accumulator and
restores summaryMsg/compactVersion on the session.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ContextBudget and ReserveTokens fields to SessionConfig for
controlling the token-based compaction threshold. Add compaction prompt
constants (preFlushPrompt, summaryPrompt, flushSkipSentinel) that will
be used by the agent compaction orchestrator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…anagement

Wire contextBudget/reserveTokens config into Agent struct, create the
compaction pipeline (pre-flush, summarize, compact), and hook it into
runLoop before appending the user message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
End-to-end tests covering the full session lifecycle: create, populate,
compact, save, load, verify, append, save again, and verify persistence
of summary and message counts across reloads. Also tests token estimation
threshold detection for compaction triggering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Mar 3, 2026

Copy link
Copy Markdown

@davexpro davexpro merged commit d828a5d into main Mar 5, 2026
7 checks passed
@davexpro davexpro deleted the feat/session-compaction branch March 5, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant