AGENTS.md
Project Identity
Project Name: ratatui_ruby
Description: A high-performance Ruby wrapper for the Ratatui TUI library.
Architecture:
-
Frontend (Ruby): Pure
Dataobjects (Ruby 3.2+) defining the View Tree. Immediate mode. -
Backend (Rust): A generic renderer using
ratatuiandmagnusthat traverses the RubyDatatree and renders to the terminal buffer.
1. File & Coding Standards
Licensing & Copyright (Strict)
Every file must begin with an SPDX-compliant header. Use the following format:
# frozen_string_literal: true # SPDX-FileCopyrightText: 2025 Kerrick Long <me@kerricklong.com> # SPDX-License-Identifier: AGPL-3.0-or-later
-
Ruby/Rust/Config files: Use comments appropriate for the language (
#or//). -
Markdown: Use HTML comment style
<!-- -->. -
Exceptions:
REUSE.tomlmanages exceptions (e.g., binary files or.gitignore).
Ruby Standards
-
Version: Strict Ruby 3.4 compatibility (Target
3.4.7as per cosmoruby). -
Linter: Run via
rake lint. You are not done until all linting passes. -
Style:
-
Use
Data.definefor all value objects (UI Nodes). (Preferclass Foo < Data.define()overFoo = Data.define() do). -
Prefer
frozen_string_literal: true. -
Use
Minitestfor testing. -
Define types in
.rbsfiles. Donβt useuntypedjust because itβs easy; be comprehensive and accurate. Do not includeinitializein.rbsfiles; useself.newfor constructors instead. -
Every line of Ruby must be covered by tests that would stand up to mutation testing. This includes all examples in the
examples/directory; they should have corresponding tests inexamples/to ensure they continue to work as intended and serve as reliable documentation. Tests must be meaningful and verify specific behavior or rendering output; simply verifying that code βdoesnβt crashβ is insufficient and unacceptable. -
Every public Ruby class/method must be documented for humans in RDoc (preferred)βnot YARDβor markdown files (fallback), and must have
*.rbstypes defined. -
Every significant architectural and design decision must be documented for contributors in markdown files. Mermaid is allowed.
-
Rust Standards
-
Crate Type:
cdylib. -
Linter:
clippyandrustfmt. -
Bindings: Use magnus.
-
Platform: Support macOS (Apple Silicon), Linux, and Windows.
-
Linker Flags: Must handle macOS
-undefined dynamic_lookup. -
Every line of Rust must be covered by tests that would stand up to mutation testing. This includes every widget implementation in
ext/ratatui_ruby/src/widgets/; each must have atestsmodule with unit tests verifying basic rendering. Tests must be meaningful; simply verifying that code βdoesnβt crashβ or βcompilesβ is insufficient.
2. Directory Structure Convention
The project follows a standard Gem layout with an ext/ directory for Rust code.
/ βββ .cargo/ # Cargo configuration (linker flags) βββ .github/ # CI/CD workflows βββ bin/ # Executables (console, setup) βββ docs/ # Documentation tree β βββ contributors/ # Design docs, ecosystem notes β βββ index.md βββ ext/ β βββ ratatui_ruby/ # RUST SOURCE CODE GOES HERE β βββ src/ β β βββ lib.rs # Entry point β βββ Cargo.toml β βββ extconf.rb # Makefile generator βββ lib/ β βββ ratatui_ruby/ β β βββ schema/ # Ruby Data definitions β β βββ version.rb β βββ ratatui_ruby.rb # Main loader βββ test/ β βββ data/ # Data-driven test files β βββ ratatui_ruby/ # Unit tests βββ vendor/ # Vendorized style configs (goodcop) βββ AGENTS.md # Context for AI agents βββ Gemfile βββ Rakefile βββ REUSE.toml # Compliance definition βββ ratatui_ruby.gemspec
3. Configuration & Tooling
Development Environment
-
Setup:
bin/setupmust handle both Bundler and Cargo dependencies. -
Pre-commit: Use
.pre-commit-config.yamlto enforcerakeandcargo fmt.
Documentation
-
Follow the
docs/structure:index.md->contributors/|quickstart.md. -
Documentation should separate βUser Guideβ (Ruby API for TUI developers) from βContributor Guideβ (Ruby/Rust/Magnus internals).
-
Donβt write .md files for something RDoc (Ruby) or rustdoc (Rust) can generate.
-
Never edit the
doc/folder directly. It is automatically generated byrake rerdoc. If you need to refresh the generated documentation, run that command instead.
4. The Ruby <-> Rust Bridge Contract
The Ruby Side (lib/)
-
Refer to docs/contributors/design/ruby_frontend.md for detailed design philosophy regarding the Data-Driven UI and Immediate Mode paradigm.
The Rust Side (ext/)
-
Refer to docs/contributors/design/rust_backend.md for detailed implementation guidelines, module structure, and rendering logic.
5. Deployment / Release
-
The gem builds a native extension.
-
Artifact naming: Ensure the output shared library matches Rubyβs expectation on macOS (rename
.dylibto.bundleif necessary during the build process inextconf.rborRakefile).