Class: Rubino::Commands::Handlers::AgentSwitch

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

Overview

The PRIMARY-agent switcher (#320), distinct from Handlers::Agents (which drills into the background ‘task` subagents). Resolves the `/agent` picker and the dynamic `/<agent-name>` commands against the live Rubino.agent_registry, returning the dispatcher’s signal vocabulary:

{select_agent: name}   pin a primary agent for the session (sticky)
{prompt:, agent:}      route THIS turn to an agent (one-shot)
:handled               listing / usage hint, no turn and no switch

The REPL applies select_agent: to the live runner + Rubino::ActiveAgent and threads agent: through run_turn — the same channel a custom command’s ‘agent:` frontmatter already used.

Instance Method Summary collapse

Constructor Details

#initialize(ui:) ⇒ AgentSwitch

Returns a new instance of AgentSwitch.



19
20
21
# File 'lib/rubino/commands/handlers/agent_switch.rb', line 19

def initialize(ui:)
  @ui = ui
end

Instance Method Details

#handle_command(name, arguments) ⇒ Object

Resolves a dynamic ‘/<agent-name>` command. Returns nil when name is not a visible agent (so the dispatcher falls through to custom commands), a select_agent: sticky switch for a bare primary, a agent: one-shot route when a message follows, or :handled with a usage hint for a bare subagent name.



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

def handle_command(name, arguments)
  agent = registry.find(name)
  return nil unless agent && !agent.hidden?

  message = arguments.to_s.strip
  return route_bare(name, agent) if message.empty?

  # One-shot route: this turn runs under <agent>'s definition.
  @ui.status("Routing this turn to agent: /#{name}")
  { prompt: message, agent: agent.name }
end

#handle_picker(arguments) ⇒ Object

‘/agent` → list switchable primaries + invokable subagents `/agent <name>` → pin a primary (returns a select_agent: signal)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubino/commands/handlers/agent_switch.rb', line 25

def handle_picker(arguments)
  name = arguments.to_s.strip.split(/\s+/).first

  if name.nil? || name.empty? || name == "list"
    show_roster
    return :handled
  end

  agent = registry.find(name)
  unless agent&.primary?
    reject_non_primary(name, agent)
    return :handled
  end

  { select_agent: agent.name }
end