Class: MessageDecorator

Inherits:
ApplicationDecorator show all
Defined in:
app/decorators/message_decorator.rb

Overview

Base decorator for Message records, providing multi-resolution rendering for the TUI and Melete. Each message type has a dedicated subclass that implements rendering methods for each view mode:

  • basic / verbose / debug — TUI display modes returning structured hashes

  • melete — Melete transcript lines as plain strings (or nil to skip)

TUI decorators return structured hashes (not pre-formatted strings) so that the TUI can style and lay out content based on semantic role, without fragile regex parsing. The TUI receives structured data via ActionCable and formats it for display.

Melete mode returns condensed single-line strings for her message transcript. Returns nil to exclude a message from her view.

Subclasses must override #render_basic. Verbose, debug, and melete modes delegate to basic until subclasses provide their own implementations.

Instantiate via message.decorateMessage#decorator_class picks the concrete subclass based on message_type.

Examples:

Decorate a message and render it

decorator = message.decorate
decorator.render("basic")  #=> {role: :user, content: "hello"} or nil

Constant Summary collapse

TOOL_ICON =
"\u{1F527}"
RETURN_ARROW =
"\u21A9"
ERROR_ICON =
"\u274C"
MIDDLE_TRUNCATION_MARKER =
"\n[...truncated...]\n"

Instance Method Summary collapse

Instance Method Details

#render(mode) ⇒ Hash, ...

Dispatches to the render method for the given view mode.

Parameters:

  • mode (String)

    one of “basic”, “verbose”, “debug”, “melete”, “mneme”

Returns:

  • (Hash, String, nil)

    structured message data (basic/verbose/debug), plain string (melete), or nil to hide the message

Raises:

  • (ArgumentError)

    if the mode is not a valid view mode



50
51
52
53
54
55
# File 'app/decorators/message_decorator.rb', line 50

def render(mode)
  method = RENDER_DISPATCH[mode]
  raise ArgumentError, "Invalid view mode: #{mode.inspect}" unless method

  public_send(method)
end

#render_basicHash?

This method is abstract.

Subclasses must implement to render the message for basic view mode.

Returns structured message data, or nil to hide the message.

Returns:

  • (Hash, nil)

    structured message data, or nil to hide the message

Raises:

  • (NotImplementedError)


59
60
61
# File 'app/decorators/message_decorator.rb', line 59

def render_basic
  raise NotImplementedError, "#{self.class} must implement #render_basic"
end

#render_debugHash?

Debug view mode with token counts and system prompts. Delegates to #render_basic until subclasses provide their own implementations.

Returns:

  • (Hash, nil)

    structured message data, or nil to hide the message



73
74
75
# File 'app/decorators/message_decorator.rb', line 73

def render_debug
  render_basic
end

#render_meleteString?

Melete view — condensed single-line string for her message transcript. Returns nil to exclude from her context. Subclasses override to provide message-type-specific formatting.

Returns:

  • (String, nil)

    formatted transcript line, or nil to skip



81
82
83
# File 'app/decorators/message_decorator.rb', line 81

def render_melete
  nil
end

#render_mnemeString, ...

Mneme memory view — transcript line for eviction/context zones. Conversation and think messages return a prefixed string. Regular tool calls return :tool_call (counter marker). Tool responses return nil (silent).

Returns:

  • (String, Symbol, nil)


90
91
92
# File 'app/decorators/message_decorator.rb', line 90

def render_mneme
  nil
end

#render_verboseHash?

Verbose view mode with timestamps and tool details. Delegates to #render_basic until subclasses provide their own implementations.

Returns:

  • (Hash, nil)

    structured message data, or nil to hide the message



66
67
68
# File 'app/decorators/message_decorator.rb', line 66

def render_verbose
  render_basic
end