Class: RubynCode::Skills::AutoSuggest

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/skills/auto_suggest.rb

Overview

Suggests skill packs based on gems detected in the project’s Gemfile.

On session start, parses the Gemfile, queries the registry for matching packs, and shows a one-time suggestion. Tracks shown suggestions in ‘.rubyn-code/suggested.json` to avoid repeating.

Constant Summary collapse

SUGGESTED_FILE =
'suggested.json'

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, registry_client: nil) ⇒ AutoSuggest

Returns a new instance of AutoSuggest.

Parameters:

  • project_root (String)
  • registry_client (RegistryClient) (defaults to: nil)


18
19
20
21
# File 'lib/rubyn_code/skills/auto_suggest.rb', line 18

def initialize(project_root:, registry_client: nil)
  @project_root = project_root
  @client = registry_client || RegistryClient.new
end

Instance Method Details

#checkString?

Check for suggestable packs and return a display message if any. Returns nil if no suggestions or if all have been shown/dismissed.

This method never raises — registry failures are silently swallowed to avoid blocking session start.

Returns:

  • (String, nil)

    suggestion message or nil



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubyn_code/skills/auto_suggest.rb', line 30

def check
  gems = parse_gemfile
  return nil if gems.empty?

  suggestions = fetch_suggestions(gems)
  return nil if suggestions.empty?

  new_suggestions = filter_shown(suggestions)
  return nil if new_suggestions.empty?

  record_shown(new_suggestions)
  format_message(new_suggestions)
rescue StandardError
  nil
end

#mark_dismissed(name) ⇒ Object

Mark a suggestion as dismissed.

Parameters:

  • name (String)

    pack name



59
60
61
62
63
64
# File 'lib/rubyn_code/skills/auto_suggest.rb', line 59

def mark_dismissed(name)
  state = load_state
  state['dismissed'] ||= []
  state['dismissed'] << name unless state['dismissed'].include?(name)
  save_state(state)
end

#mark_installed(name) ⇒ Object

Mark a pack as installed so it won’t be suggested again.

Parameters:

  • name (String)

    pack name



49
50
51
52
53
54
# File 'lib/rubyn_code/skills/auto_suggest.rb', line 49

def mark_installed(name)
  state = load_state
  state['installed'] ||= []
  state['installed'] << name unless state['installed'].include?(name)
  save_state(state)
end