Class: Gem::Skill::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/skill/generator.rb

Overview

Drives the LLM pipeline: fetches docs, generates a SKILL.md, caches it.

Constant Summary collapse

DEFAULT_MODEL =
ENV.fetch("GEMSKILL_MODEL", "gpt-5.5")
MAX_SOURCE_CHARS =

guard against enormous READMEs blowing the context window

60_000
SYSTEM_INSTRUCTIONS =
<<~SYSTEM
  You are a Ruby gem documentation specialist who generates Claude Code skill files.
  A skill file gives Claude Code deep, practical knowledge about a library so it can
  use it correctly without re-reading source docs. Be accurate, concise, and complete
  for the most common use cases. No filler, no marketing language.
SYSTEM
SKILL_PROMPT =
<<~PROMPT
  Generate a SKILL.md for the Ruby gem "%<gem_name>s" version %<version>s.

  Output raw Markdown directly. Do NOT wrap the output in a code fence or any
  other container — the file is Markdown, so no ```markdown wrapper.

  Begin with a top-level heading identifying the gem and version, then use exactly these sections:

  # %<gem_name>s v%<version>s

  ## Overview
  One paragraph: what the gem does and when to reach for it.

  ## Installation
  Exact Gemfile/gemspec lines and any required post-install steps.

  ## Core API
  The most important classes, methods, and options. Show real method signatures
  and return values. Prefer code over prose.

  ## Common Patterns
  The 3-5 most frequent real-world usage patterns with working code examples.

  ## Gotchas & Edge Cases
  Things that surprise developers: unexpected defaults, version-specific behavior,
  thread safety concerns, performance cliffs, encoding issues.

  ## Configuration
  Initializer patterns, environment variables, defaults worth knowing.

  ## Testing
  How to test code that uses this gem: mocks, fakes, fixtures, VCR patterns.

  Synthesize the sources below — do not copy them verbatim.
  Write as a knowledgeable colleague, not a marketing document.

  ---

  %<sources>s
PROMPT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_name, version, model: DEFAULT_MODEL) ⇒ Generator

Returns a new instance of Generator.



61
62
63
64
65
# File 'lib/gem/skill/generator.rb', line 61

def initialize(gem_name, version, model: DEFAULT_MODEL)
  @gem_name = gem_name
  @version  = version
  @model    = model
end

Instance Attribute Details

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



59
60
61
# File 'lib/gem/skill/generator.rb', line 59

def gem_name
  @gem_name
end

#modelObject (readonly)

Returns the value of attribute model.



59
60
61
# File 'lib/gem/skill/generator.rb', line 59

def model
  @model
end

#versionObject (readonly)

Returns the value of attribute version.



59
60
61
# File 'lib/gem/skill/generator.rb', line 59

def version
  @version
end

Instance Method Details

#generate(force: false, &block) ⇒ Object

Generate and cache a SKILL.md. Returns the skill content string. Pass a block to stream output chunks to the caller for live feedback.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gem/skill/generator.rb', line 69

def generate(force: false, &block)
  return Cache.read(gem_name, version) if Cache.cached?(gem_name, version) && !force

  sources = Fetcher.new(gem_name, version).fetch_all
  raise Error, "No documentation found for #{gem_name} #{version}" if sources.empty?

  skill_content = block ? call_llm_streaming(sources, &block) : call_llm(sources)
  Cache.store(gem_name, version, skill_content, { sources: sources.keys.map(&:to_s), model: model })
  skill_content
rescue RubyLLM::Error => e
  raise Error, e.message
end