Class: Aidp::CLI::ToolsCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/cli/tools_command.rb

Overview

CLI commands for managing tool metadata

Provides commands for:

  • aidp tools lint - Validate all metadata

  • aidp tools info <id> - Display tool details

  • aidp tools reload - Force cache regeneration

  • aidp tools list - List all tools

Instance Method Summary collapse

Constructor Details

#initialize(project_dir: Dir.pwd, prompt: TTY::Prompt.new) ⇒ ToolsCommand

Initialize tools command

Parameters:

  • project_dir (String) (defaults to: Dir.pwd)

    Project directory path

  • prompt (TTY::Prompt) (defaults to: TTY::Prompt.new)

    TTY prompt instance



24
25
26
27
# File 'lib/aidp/cli/tools_command.rb', line 24

def initialize(project_dir: Dir.pwd, prompt: TTY::Prompt.new)
  @project_dir = project_dir
  @prompt = prompt
end

Instance Method Details

#run(args) ⇒ Integer

Run tools command

Parameters:

  • args (Array<String>)

    Command arguments

Returns:

  • (Integer)

    Exit code



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aidp/cli/tools_command.rb', line 33

def run(args)
  subcommand = args.shift

  case subcommand
  when "lint"
    run_lint
  when "info"
    tool_id = args.shift
    unless tool_id
      @prompt.say("Error: tool ID required")
      @prompt.say("Usage: aidp tools info <tool_id>")
      return 1
    end
    run_info(tool_id)
  when "reload"
    run_reload
  when "list"
    run_list
  when nil, "help", "--help", "-h"
    show_help
    0
  else
    @prompt.say("Unknown subcommand: #{subcommand}")
    show_help
    1
  end
end

#run_info(tool_id) ⇒ Object

Run info command

Parameters:

  • tool_id (String)

    Tool ID



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/aidp/cli/tools_command.rb', line 115

def run_info(tool_id)
  Aidp.log_info("tools", "Showing tool info", tool_id: tool_id)

  cache = create_cache
  query = Metadata::Query.new(cache: cache)

  tool = query.find_by_id(tool_id)

  unless tool
    @prompt.error("Tool not found: #{tool_id}")
    return 1
  end

  display_tool_details(tool)

  0
end

#run_lintObject

Run lint command



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/aidp/cli/tools_command.rb', line 76

def run_lint
  Aidp.log_info("tools", "Running tool metadata lint")

  @prompt.say("\nValidating tool metadata...")

  cache = create_cache
  query = Metadata::Query.new(cache: cache)

  begin
    query.directory
  rescue => e
    @prompt.error("Failed to load tool directory: #{e.message}")
    Aidp.log_error("tools", "Lint failed", error: e.message)
    return 1
  end

  # Reload to get fresh validation
  tools = load_all_tools

  validator = Metadata::Validator.new(tools)
  results = validator.validate_all

  # Display results
  display_lint_results(results)

  # Write error log if there are errors
  invalid_results = results.reject(&:valid)
  if invalid_results.any?
    log_path = File.join(@project_dir, ".aidp", "logs", "metadata_errors.log")
    validator.write_error_log(results, log_path)
    @prompt.warn("\nError log written to: #{log_path}")
  end

  invalid_results.empty? ? 0 : 1
end

#run_listObject

Run list command



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/aidp/cli/tools_command.rb', line 154

def run_list
  Aidp.log_info("tools", "Listing all tools")

  cache = create_cache
  query = Metadata::Query.new(cache: cache)

  query.directory
  stats = query.statistics

  @prompt.say("\nTool Directory Statistics:")
  @prompt.say("  Total tools: #{stats["total_tools"]}")
  @prompt.say("  By type:")
  stats["by_type"].each do |type, count|
    @prompt.say("    #{type}: #{count}")
  end

  @prompt.say("\nAll Tools:")

  # Group by type
  %w[skill persona template].each do |type|
    tools = query.find_by_type(type)
    next if tools.empty?

    @prompt.say("\n#{type.capitalize}s (#{tools.size}):")
    display_tools_table(tools)
  end

  0
end

#run_reloadObject

Run reload command



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/aidp/cli/tools_command.rb', line 134

def run_reload
  Aidp.log_info("tools", "Reloading tool directory")

  @prompt.say("\nRegenerating tool directory cache...")

  cache = create_cache

  begin
    cache.reload
    @prompt.ok("Tool directory cache regenerated successfully")
  rescue => e
    @prompt.error("Failed to reload cache: #{e.message}")
    Aidp.log_error("tools", "Reload failed", error: e.message)
    return 1
  end

  0
end

#show_helpObject

Show help message



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aidp/cli/tools_command.rb', line 62

def show_help
  @prompt.say("\nAIDP Tools Management")
  @prompt.say("\nUsage:")
  @prompt.say("  aidp tools lint           Validate all tool metadata")
  @prompt.say("  aidp tools info <id>      Show detailed tool information")
  @prompt.say("  aidp tools reload         Force regenerate tool directory cache")
  @prompt.say("  aidp tools list           List all available tools")
  @prompt.say("\nExamples:")
  @prompt.say("  aidp tools lint")
  @prompt.say("  aidp tools info ruby_rspec_tdd")
  @prompt.say("  aidp tools reload")
end