Skip to content

feat: gem-level credential configuration (Locallingo.configure + .locallingo.rb) - #3

Merged
mhenrixon merged 4 commits into
mainfrom
feat/gem-level-credentials
Jul 15, 2026
Merged

feat: gem-level credential configuration (Locallingo.configure + .locallingo.rb)#3
mhenrixon merged 4 commits into
mainfrom
feat/gem-level-credentials

Conversation

@mhenrixon

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #2, which only filled RubyLLM's key from process ENV. Juraj's report: zazu keeps its Anthropic key in AppConf, and bin/lingo is a plain Bundler binstub — no Rails boot, no dotenv — so standalone CLI runs could never see it. The gem needed a way to receive credentials outside a Rails initializer.

  • Locallingo.configure { |c| c.anthropic_api_key = ... } — new Locallingo::Settings with per-provider api-key accessors (same provider set as CREDENTIAL_ENV). Values are Strings or callables; callables are resolved fresh on every LLM call, never memoized, so keys can come from sources that rotate or aren't ready at configure time.
  • .locallingo.rb setup file — the CLI loads it from the project root before dispatch. Absent file is silent; errors in it propagate loudly.
  • Resolution order (first non-blank key wins): Locallingo.configure → host RubyLLM.config (Rails initializer) → ENV. credentials? / ensure_credentials! now see all three sources, and the missing-credentials error names each option.
  • Docs: providers/installation/configuration pages, README, CHANGELOG. Version → 0.3.0 (new public API).

Test plan

  • TDD throughout — 79 examples, 0 failures; RuboCop clean (bundle exec rake)
  • Docs pages render (booted the docs app, all three pages 200 with new content)
  • End-to-end in zazu: with ANTHROPIC_API_KEY unset in the shell, bin/lingo translate --dry-run previously failed with No credentials for provider :anthropic; with this branch + a .locallingo.rb (Dotenv → AppConf → Locallingo.configure) it completes, and the resolved key is the real 108-char sk-ant-api… from .env via AppConf.anthropic_api_key

Zazu-side wiring PR follows separately.

Keys were only ever read from process ENV, so apps whose credentials live
elsewhere (an app config object, Rails credentials, a vault) had no way to
hand them to the gem outside a Rails initializer.

- New Locallingo::Settings with per-provider api-key accessors; values are
  Strings or callables (resolved fresh on every LLM call, never memoized)
- Locallingo.configure { |c| c.anthropic_api_key = ... } yields the memoized
  settings; reset_settings! for test isolation
- Providers::RubyLLM resolves keys across three sources, first wins:
  Locallingo settings -> host RubyLLM.config -> ENV. credentials? and
  ensure_credentials! now see all three, and the error message names each
  option.
bin/lingo never boots Rails, so initializers can't configure credentials for
standalone runs. The CLI now loads an optional .locallingo.rb from the
project root (next to .locallingo.yml) before dispatching — the place for
Locallingo.configure. Absent file is silent; errors propagate loudly.
@mhenrixon
mhenrixon merged commit 8c3a85d into main Jul 15, 2026
3 checks passed
@mhenrixon
mhenrixon deleted the feat/gem-level-credentials branch July 15, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant