Class: Yorishiro::Compactor
- Inherits:
-
Object
- Object
- Yorishiro::Compactor
- Defined in:
- lib/yorishiro/compactor.rb
Overview
Summarizes older conversation history into a compact summary so long sessions stay within the model's context window (similar to Claude Code's auto-compaction). Uses the active provider to generate the summary.
Constant Summary collapse
- KEEP_RECENT_ROUNDS =
2- SUMMARY_SYSTEM_PROMPT =
<<~PROMPT You compress conversation history for an AI coding assistant. Produce a concise but complete summary that preserves everything needed to continue the work: the user's goals and requests, key decisions made, files and code examined or changed, tool results that still matter, and any unresolved questions or next steps. Prefer terse bullet points. Do not add commentary or ask questions — output only the summary. PROMPT
- SUMMARY_INSTRUCTION =
"Summarize the following conversation transcript so the assistant can continue seamlessly:"
Instance Method Summary collapse
-
#compact(conversation, keep_recent_rounds: KEEP_RECENT_ROUNDS) ⇒ Object
Compact the given conversation in place.
-
#initialize(provider) ⇒ Compactor
constructor
A new instance of Compactor.
Constructor Details
#initialize(provider) ⇒ Compactor
Returns a new instance of Compactor.
21 22 23 |
# File 'lib/yorishiro/compactor.rb', line 21 def initialize(provider) @provider = provider end |
Instance Method Details
#compact(conversation, keep_recent_rounds: KEEP_RECENT_ROUNDS) ⇒ Object
Compact the given conversation in place. Returns the number of messages that were summarized away (0 if nothing was compacted).
27 28 29 30 31 |
# File 'lib/yorishiro/compactor.rb', line 27 def compact(conversation, keep_recent_rounds: KEEP_RECENT_ROUNDS) conversation.compact!(keep_recent_rounds: keep_recent_rounds) do || summarize() end end |