Module: RubynCode::Agent::ResponseModes

Defined in:
lib/rubyn_code/agent/response_modes.rb

Overview

Dynamically adjusts response verbosity based on the current task type. Injects mode-specific instructions into the system prompt to reduce unnecessary output tokens without losing useful information.

Constant Summary collapse

MODES =
{
  implementing: {
    label: 'implementing',
    instruction: 'Write the code. Brief comment on non-obvious decisions only. No preamble or recap.'
  },
  explaining: {
    label: 'explaining',
    instruction: 'Explain clearly and concisely. Use examples from this codebase when possible.'
  },
  reviewing: {
    label: 'reviewing',
    instruction: 'List findings with severity, file, line. No filler between findings.'
  },
  exploring: {
    label: 'exploring',
    instruction: 'Summarize structure. Use tree format. Note patterns and anti-patterns briefly.'
  },
  debugging: {
    label: 'debugging',
    instruction: 'State most likely cause first. Then evidence. Then fix. No preamble.'
  },
  testing: {
    label: 'testing',
    instruction: 'Write specs directly. Minimal explanation. Only note non-obvious test setup.'
  },
  chatting: {
    label: 'chatting',
    instruction: 'Respond naturally and concisely.'
  }
}.freeze
DEFAULT_MODE =
:chatting

Class Method Summary collapse

Class Method Details

.detect(message, tool_calls: []) ⇒ Symbol

Detects the response mode from the user’s message content.

Parameters:

  • message (String)

    the user’s input

  • tool_calls (Array) (defaults to: [])

    recent tool calls (for context)

Returns:

  • (Symbol)

    one of the MODES keys



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubyn_code/agent/response_modes.rb', line 48

def detect(message, tool_calls: []) # rubocop:disable Metrics/CyclomaticComplexity -- mode detection dispatch
  return :implementing if implementation_signal?(message)
  return :debugging    if debugging_signal?(message)
  return :reviewing    if reviewing_signal?(message)
  return :testing      if testing_signal?(message)
  return :exploring    if exploring_signal?(message)
  return :explaining   if explaining_signal?(message)

  recent_tool = tool_calls.last
  return detect_from_tool(recent_tool) if recent_tool

  DEFAULT_MODE
end

.instruction_for(mode) ⇒ String

Returns the instruction text for a given mode.

Parameters:

  • mode (Symbol)

Returns:

  • (String)


66
67
68
69
# File 'lib/rubyn_code/agent/response_modes.rb', line 66

def instruction_for(mode)
  config = MODES.fetch(mode, MODES[DEFAULT_MODE])
  "\n## Response Mode: #{config[:label]}\n#{config[:instruction]}"
end