Module: RubynCode::Context::ManualCompact

Defined in:
lib/rubyn_code/context/manual_compact.rb

Overview

LLM-driven summarization triggered explicitly by the user or agent via the /compact command. Identical to AutoCompact but supports an optional custom focus prompt so the user can steer what gets preserved.

Constant Summary collapse

BASE_INSTRUCTION =
<<~PROMPT
  You are a context compaction assistant. Summarize the following conversation transcript for continuity. Cover exactly three areas:

  1) **What was accomplished** - completed tasks, files changed, problems solved
  2) **Current state** - what the user/agent is working on right now, any pending actions
  3) **Key decisions made** - architectural choices, user preferences, constraints established

  Be concise but preserve all details needed to continue the work seamlessly. Use bullet points.
PROMPT
MAX_TRANSCRIPT_CHARS =
80_000

Class Method Summary collapse

Class Method Details

.call(messages, llm_client:, transcript_dir: nil, focus: nil) ⇒ Array<Hash>

Compacts the conversation by summarizing it through the LLM.

Parameters:

  • messages (Array<Hash>)

    current conversation messages

  • llm_client (#chat)

    an LLM client that responds to #chat

  • transcript_dir (String, nil) (defaults to: nil)

    directory to save full transcript before compaction

  • focus (String, nil) (defaults to: nil)

    optional user-supplied focus prompt to guide summarization

Returns:

  • (Array<Hash>)

    new messages array containing only the summary



31
32
33
34
35
36
37
38
39
# File 'lib/rubyn_code/context/manual_compact.rb', line 31

def self.call(messages, llm_client:, transcript_dir: nil, focus: nil)
  save_transcript(messages, transcript_dir) if transcript_dir

  transcript_text = serialize_tail(messages, MAX_TRANSCRIPT_CHARS)
  instruction = build_instruction(focus)
  summary = request_summary(transcript_text, instruction, llm_client)

  [{ role: 'user', content: "[Context compacted — manual]\n\n#{summary}" }]
end