Module: Clacky::SearchConfig
- Defined in:
- lib/clacky/search_config.rb
Overview
Search provider selection, backed by ~/.clacky/search.yml.
The built-in DuckDuckGo/Bing scrapers need no configuration and stay the
default. Pointing provider at a script in ~/.clacky/searchers/ routes
web_search through an API-backed engine instead, which is what users who
want higher-quality results (or China-reachable ones) reach for.
search.yml schema:
provider: tavily — basename of a script in ~/.clacky/searchers/;
blank or missing means built-in engines only
key: tvly-xxx — credential handed to that script via env
The directory is the registry: dropping my_engine.rb into
~/.clacky/searchers/ and setting provider: my_engine is all it takes,
mirroring how ~/.clacky/skills/ and ~/.clacky/parsers/ work.
Constant Summary collapse
- CONFIG_PATH =
File.("~/.clacky/search.yml").freeze
Class Method Summary collapse
- .key ⇒ Object
-
.load ⇒ Hash
{ "provider" => String, "key" => String }.
- .save(provider:, key:) ⇒ Object
-
.script_path ⇒ Object
Absolute path of the configured searcher, or nil when unset/missing.
Class Method Details
.key ⇒ Object
52 53 54 |
# File 'lib/clacky/search_config.rb', line 52 def key load["key"] end |
.load ⇒ Hash
Returns { "provider" => String, "key" => String }.
27 28 29 30 31 32 33 34 |
# File 'lib/clacky/search_config.rb', line 27 def load raw = File.exist?(CONFIG_PATH) ? YAML.load_file(CONFIG_PATH) : nil return { "provider" => "", "key" => "" } unless raw.is_a?(Hash) { "provider" => raw["provider"].to_s.strip, "key" => raw["key"].to_s.strip } rescue StandardError { "provider" => "", "key" => "" } end |
.save(provider:, key:) ⇒ Object
36 37 38 39 40 |
# File 'lib/clacky/search_config.rb', line 36 def save(provider:, key:) FileUtils.mkdir_p(File.dirname(CONFIG_PATH)) File.write(CONFIG_PATH, { "provider" => provider.to_s.strip, "key" => key.to_s.strip }.to_yaml) File.chmod(0o600, CONFIG_PATH) end |
.script_path ⇒ Object
Absolute path of the configured searcher, or nil when unset/missing. A provider naming a script that isn't installed is treated as unset so web_search silently falls back instead of erroring on every search.
45 46 47 48 49 50 |
# File 'lib/clacky/search_config.rb', line 45 def script_path name = load["provider"] return nil if name.empty? Clacky::Utils::SearcherManager.path_for(name) end |