Class: Rubino::Commands::Handlers::Sessions

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/commands/handlers/sessions.rb

Overview

The ‘/sessions` list/show/delete/picker surface plus the `/probe` and `/branch` REPL signals, extracted from Commands::Executor (batch B).

No-arg = list recent + how to resume; arg = resolve and resume in place. Resuming returns a resume_session_id: signal the REPL acts on by rebuilding its runner on that session (history replays). Reuses Session::Repository#list and #find_by_id_or_title (which already raises AmbiguousSessionError on >1 match).

The management verbs (#183) reuse the CLI subcommands’ logic (CLI::SessionCommand.render / .destroy_with_confirm — ONE rendering and ONE delete flow for both surfaces):

/sessions                → list (picker on a TTY) + resume
/sessions --all          → list without the row cap
/sessions show <id>      → details, without switching into it
/sessions delete <id>    → delete (asks to confirm)
/sessions <id|title>     → resume

Instance Method Summary collapse

Constructor Details

#initialize(ui:, runner:) ⇒ Sessions

Returns a new instance of Sessions.



27
28
29
30
# File 'lib/rubino/commands/handlers/sessions.rb', line 27

def initialize(ui:, runner:)
  @ui = ui
  @runner = runner
end

Instance Method Details

#handle_branch(arguments) ⇒ Object

‘/branch [name]` — fork the current session here into a NEW saved one and switch into it. The REPL holds the runner/session, so we just pass the optional title along on the branch signal.



61
62
63
64
# File 'lib/rubino/commands/handlers/sessions.rb', line 61

def handle_branch(arguments)
  title = arguments.to_s.strip
  { branch: true, title: title.empty? ? nil : title }
end

#handle_probe(arguments) ⇒ Object

‘/probe <text>` — the discoverable alias for the `? ` prefix. Bare `/probe` only teaches the prefix (the one-keystroke common case); with text, signal the REPL to run the ephemeral side-inference and discard.



47
48
49
50
51
52
53
54
55
56
# File 'lib/rubino/commands/handlers/sessions.rb', line 47

def handle_probe(arguments)
  text = arguments.to_s.strip
  if text.empty?
    @ui.info("Ask an ephemeral side-question that is NOT saved to this session.")
    @ui.info("Tip: just start a line with '? ' — e.g.  ? is this lib MIT or GPL?")
    return :handled
  end

  { probe: text }
end

#handle_sessions(arguments) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubino/commands/handlers/sessions.rb', line 32

def handle_sessions(arguments)
  tokens = arguments.to_s.strip.split(/\s+/)
  all    = tokens.delete("--all") ? true : false
  return list_sessions(all: all) if tokens.empty?

  case tokens.first
  when "show"   then session_verb(tokens[1..].join(" "), "show") { |s| CLI::SessionCommand.render(s, ui: @ui) }
  when "delete" then session_verb(tokens[1..].join(" "), "delete") { |s| delete_session(s) }
  else resume_session(tokens.join(" "))
  end
end