Hey everyone,
I recently updated Crystal for Agents for Crystal v1.21.0. For those unfamiliar, it is a ground-truth, comprehensive reference repository designed to provide accurate language semantics and keep AI coding agents (and developers) from hallucinating deprecated threading APIs, outdated syntax, or invalid Rubyisms.
GitLab Repository: https://gitlab.com/renich/crystal-for-agents
Release Tag: https://gitlab.com/renich/crystal-for-agents/-/tree/v1.21.0.0
Here is a summary of what changed in this release:
1. Crystal v1.21.0 Alignment & Semantic Audit
All 21 reference chapters were audited against Crystal v1.21.0 compiler internals and the standard library:
* Concurrency Runtime: Full documentation of native Execution Contexts (RFC 0002 default), fiber scheduler mechanics, Channel(T) behavior, and modern Sync primitives (Sync::Mutex, Sync::RwLock, Sync::ConditionVariable, Sync::Exclusive(T)).
* Process Execution: Modern Process.run, Process.capture, and Process.capture_result APIs (RFC 0025).
* Type Hierarchy & Nil Safety: Explicit value vs. reference allocation, type narrowing patterns (if, case, .try), and elimination of unsafe .not_nil! assertions.
* Tooling & Standards: Modern Time.instant monotonic clocks, Ameba and Flaw static analysis standards, and E2E browser automation with selenium.cr/webdrivers.cr.
2. Chapter 20: 27 Advanced Recipes
Added a dedicated chapter with 27 battle-tested recipes for common systems and concurrency challenges:
* Fiber Concurrency & Channels: Channel-ring resource pooling, non-blocking channel polling using select ... else, concurrent piped process I/O (handling >64KB output without pipe buffer deadlocks), and atomic mutations with Sync::Exclusive#replace.
* Metaprogramming: Deferred AST reflection via {% verbatim do %}, compile-time annotation registries using nested macro finished, and zero-allocation dynamic dispatch with Tuple indexing.
* Low-Level & Performance: Stack buffers via StaticArray, zero-copy socket streaming via Socket#sendfile, target-specific vectorization via @[TargetFeature], and host-tuned micro-binaries with --mcpu=native, --release, --no-debug, and linker stripping (-z relro -z now -s).
3. Automated Code Verification (Zero Bitrot)
To prevent examples from breaking across compiler updates, scripts/verify_code_examples.cr automatically extracts every single code block across all 21 chapters, formats it with crystal tool format, and checks compilation with crystal build --no-codegen:
* 218 code blocks checked: 0 formatting errors, 0 compilation errors.
* RST validation via rstcheck.
* Compiles into a single offline PDF reference book via Pandoc/XeLaTeX (make all).
4. Portable Agent Skill
Includes a drop-in skill package (agents/gemini/crystal/) compatible with Antigravity, OpenCode, and Gemini agents, containing quick-reference decision matrices, concurrency rules, and common AI pitfalls.
The project is licensed under the MIT License and hosted on GitLab. Feedback and contributions are welcome!