Class: Askcii::Commands::ClearHistoryCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/askcii/commands/clear_history_command.rb

Overview

Clears conversation history for the current session

Instance Attribute Summary

Attributes inherited from BaseCommand

#cli, #config

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Askcii::Commands::BaseCommand

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/askcii/commands/clear_history_command.rb', line 7

def execute
  verbose "Clearing history for session: #{session_context}"

  chat = Chat.find(context: session_context)

  unless chat
    puts "No session found to clear."
    exit 0
  end

  message_count = chat.messages.count

  # Delete all messages for this chat
  chat.messages_dataset.delete

  # Delete the chat itself
  chat.delete

  puts "Cleared session '#{session_context}' (#{message_count} messages removed)"

  exit 0
end