Class: RubynCode::Context::Compactor
- Inherits:
-
Object
- Object
- RubynCode::Context::Compactor
- Defined in:
- lib/rubyn_code/context/compactor.rb
Overview
Facade that coordinates the three compaction strategies: micro (every turn), auto (when threshold is exceeded), and manual (user-triggered via /compact).
Constant Summary collapse
- CHARS_PER_TOKEN =
4
Instance Method Summary collapse
-
#auto_compact!(messages) ⇒ Array<Hash>
Runs LLM-driven auto-compaction, replacing the full conversation with a continuity summary.
-
#initialize(llm_client:, threshold: 50_000, transcript_dir: nil) ⇒ Compactor
constructor
A new instance of Compactor.
-
#manual_compact!(messages, focus: nil) ⇒ Array<Hash>
Runs LLM-driven manual compaction, optionally guided by a focus prompt.
-
#micro_compact!(messages) ⇒ Integer
Runs zero-cost micro-compaction on old tool results.
-
#should_auto_compact?(messages) ⇒ Boolean
Checks whether the estimated token count for the messages exceeds the configured threshold.
Constructor Details
#initialize(llm_client:, threshold: 50_000, transcript_dir: nil) ⇒ Compactor
Returns a new instance of Compactor.
15 16 17 18 19 |
# File 'lib/rubyn_code/context/compactor.rb', line 15 def initialize(llm_client:, threshold: 50_000, transcript_dir: nil) @llm_client = llm_client @threshold = threshold @transcript_dir = transcript_dir end |
Instance Method Details
#auto_compact!(messages) ⇒ Array<Hash>
Runs LLM-driven auto-compaction, replacing the full conversation with a continuity summary. Returns a new messages array.
36 37 38 39 40 41 42 43 44 |
# File 'lib/rubyn_code/context/compactor.rb', line 36 def auto_compact!() ensure_llm_client! AutoCompact.call( , llm_client: @llm_client, transcript_dir: @transcript_dir ) end |
#manual_compact!(messages, focus: nil) ⇒ Array<Hash>
Runs LLM-driven manual compaction, optionally guided by a focus prompt. Returns a new messages array.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubyn_code/context/compactor.rb', line 53 def manual_compact!(, focus: nil) ensure_llm_client! ManualCompact.call( , llm_client: @llm_client, transcript_dir: @transcript_dir, focus: focus ) end |
#micro_compact!(messages) ⇒ Integer
Runs zero-cost micro-compaction on old tool results. Mutates messages in place and returns the count of compacted results.
26 27 28 |
# File 'lib/rubyn_code/context/compactor.rb', line 26 def micro_compact!() MicroCompact.call() end |
#should_auto_compact?(messages) ⇒ Boolean
Checks whether the estimated token count for the messages exceeds the configured threshold.
69 70 71 |
# File 'lib/rubyn_code/context/compactor.rb', line 69 def should_auto_compact?() estimated_tokens() > @threshold end |