Class: Explore::Cli::CommandCatalog

Inherits:
Object
  • Object
show all
Defined in:
lib/explore/cli/command_catalog.rb

Class Method Summary collapse

Class Method Details

.agent_help_payload(definition) ⇒ Object



78
79
80
81
82
83
# File 'lib/explore/cli/command_catalog.rb', line 78

def agent_help_payload(definition)
  payload = definition ? definition.dup : root_payload
  payload[:version] = 1
  payload[:generated_by] = definition ? "explore #{definition.fetch(:command)} --help --agent" : "explore --help --agent"
  payload
end

.commandsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/explore/cli/command_catalog.rb', line 7

def commands
  @commands ||= [
    setup_command,
    setup_claude_command,
    register_command,
    ,
    logout_command,
    whoami_command,
    commands_command,
    export_profile_command,
    validate_command,
    preview_profile_command,
    apply_command,
    profile_inspect_command,
    content_list_command,
    content_create_draft_command,
    content_propose_update_command,
    drafts_list_command,
    drafts_inspect_command,
    drafts_apply_command,
    drafts_apply_preview_command,
    drafts_update_command,
    drafts_archive_command,
    onboarding_status_command,
    manifest_next_actions_command,
    notion_sync_status_command,
    publish_preview_command,
    version_command
  ]
end

.commands_payloadObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/explore/cli/command_catalog.rb', line 59

def commands_payload
  {
    version: 1,
    generated_by: "explore commands --json",
    agent_help_usage: "explore <command> --help --agent",
    commands: commands.map do |definition|
      {
        command: definition.fetch(:command),
        summary: definition.fetch(:summary),
        usage: definition.fetch(:usage),
        auth_requirements: definition.fetch(:auth_requirements),
        output_modes: definition.fetch(:output_modes),
        side_effects: definition.fetch(:side_effects),
        related_commands: definition.fetch(:related_commands)
      }
    end
  }
end

.commands_textObject



85
86
87
88
89
90
91
92
93
# File 'lib/explore/cli/command_catalog.rb', line 85

def commands_text
  lines = [ "Available Explore commands:" ]
  commands.each do |definition|
    lines << format("%-32s %s", definition.fetch(:command), definition.fetch(:summary))
  end
  lines << ""
  lines << "Machine-readable discovery: explore commands --json"
  lines.join("\n")
end

.help_text(definition) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/explore/cli/command_catalog.rb', line 95

def help_text(definition)
  payload = definition ? definition : root_payload
  lines = []
  lines << payload.fetch(:summary)
  lines << ""
  lines << "Usage: #{payload.fetch(:usage)}"
  if payload[:arguments]&.any?
    lines << ""
    lines << "Arguments:"
    payload.fetch(:arguments).each do |entry|
      lines << "  #{entry.fetch(:name)}  #{entry.fetch(:summary)}"
    end
  end
  if payload[:flags]&.any?
    lines << ""
    lines << "Flags:"
    payload.fetch(:flags).each do |entry|
      lines << "  #{entry.fetch(:name)}  #{entry.fetch(:summary)}"
    end
  end
  if payload[:examples]&.any?
    lines << ""
    lines << "Examples:"
    payload.fetch(:examples).each do |entry|
      lines << "  #{entry}"
    end
  end
  if payload[:related_commands]&.any?
    lines << ""
    lines << "Related:"
    payload.fetch(:related_commands).each do |entry|
      lines << "  #{entry}"
    end
  end
  lines.join("\n")
end

.resolve(arguments) ⇒ Object



52
53
54
55
56
57
# File 'lib/explore/cli/command_catalog.rb', line 52

def resolve(arguments)
  tokens = Array(arguments).reject { |token| token.start_with?("-") }
  commands
    .select { |definition| tokens[0, definition.fetch(:path).length] == definition.fetch(:path) }
    .max_by { |definition| definition.fetch(:path).length }
end

.root_payloadObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/explore/cli/command_catalog.rb', line 38

def root_payload
  {
    command: "explore",
    summary: "Explore CLI for agent-readable profile, onboarding, preview, and draft workflows.",
    usage: "explore <command> [subcommand] [flags]",
    examples: [
      "explore setup",
      "explore setup claude",
      "explore commands --json"
    ],
    related_commands: commands.map { |definition| definition.fetch(:command) }
  }
end