feature/diffusion-vision
name: sdk-ruby-gem description: Build and publish the onde-inference Ruby gem (Magnus-based native extension). Use when working on the Ruby SDK under sdk/gem/, adding Ruby-exposed functions, or publishing to RubyGems. allowed-tools: Read, Write, Edit, Glob, Grep, Bash
user-invocable: true
Skill: Ruby Gem SDK (sdk/gem/)
What This Is
A Magnus-based Ruby native extension that exposes Onde's HuggingFace cache management and model metadata to Ruby. The gem is named onde-inference on RubyGems. It does not expose the ChatEngine / OndeChatEngine — it is a cache + model metadata utility layer.
Source Layout
sdk/gem/
├── Cargo.toml # Rust extension crate (magnus + onde dep)
├── Gemfile
├── Rakefile # `rake compile` → builds the .so via rb-sys-dock
├── onde-inference.gemspec
├── bin/
│ ├── console # irb + require 'onde'
│ └── setup # bundle install + rake compile
├── ext/onde/ # Rust extension source
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs # #[magnus::init] entry point
└── lib/
└── onde/
└── version.rb
Build Commands
cd sdk/gem
# First-time setup
bin/setup # bundle install + rake compile
# Recompile after Rust changes
bundle exec rake compile
# Interactive console
bin/console
# Verify
bundle exec ruby -e "require 'onde'; puts Onde::VERSION; puts Onde::SUPPORTED_MODELS"
Key Facts
- Magnus is the Rust↔Ruby binding layer (
magnuscrate). All Ruby-visible types are wrapped with#[magnus::init]andwrap_class!/rb_class!macros. - The gem depends on
ondeas a relative path insdk/gem/ext/onde/Cargo.toml— never use a published git ref here during development. rb-sysdrivesrake compile— it invokescargo buildwith the correct Ruby extension flags.- The gem is published as
onde-inferenceon RubyGems (gem push onde-inference-*.gem). Onde::SUPPORTED_MODELSis a Ruby Array of model ID strings matchingonde::inference::models::SUPPORTED_MODELS.- Cache functions (
list_local_models,list_supported_models,delete_model,diagnose_cache,repair_symlinks) are exposed as module-level methods under theOndenamespace.
Pitfalls
rake compilemust be re-run after any change to Rust source underext/onde/src/— the gem does not hot-reload.- On macOS,
LIBRARY_PATHandDYLD_LIBRARY_PATHmust include the Ruby lib path if linking fails at test time. - Magnus
Value/RArray/RHashtypes are notSend— do not store them across Ruby GC boundaries. bundle execis required for all rake/ruby invocations so the correct gem/ruby version is used.onde-inference(hyphen) on RubyGems;require 'onde'(no hyphen, no suffix) in Ruby code.