steep-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +18 -0
  3. data/LICENSE.md +21 -0
  4. data/README.md +396 -0
  5. data/exe/steep-kit +12 -0
  6. data/lib/steep_kit/alias_skip.rb +41 -0
  7. data/lib/steep_kit/check.rb +62 -0
  8. data/lib/steep_kit/cli.rb +110 -0
  9. data/lib/steep_kit/config.rb +139 -0
  10. data/lib/steep_kit/constant_literal_inference.rb +33 -0
  11. data/lib/steep_kit/constant_table.rb +152 -0
  12. data/lib/steep_kit/conventions.rb +175 -0
  13. data/lib/steep_kit/dynamic_superclasses.rb +26 -0
  14. data/lib/steep_kit/error.rb +9 -0
  15. data/lib/steep_kit/fast.rb +113 -0
  16. data/lib/steep_kit/generate.rb +55 -0
  17. data/lib/steep_kit/lint_constant_access.rb +181 -0
  18. data/lib/steep_kit/lint_inline.rb +177 -0
  19. data/lib/steep_kit/literal_inference.rb +143 -0
  20. data/lib/steep_kit/mixin_inference/installer.rb +153 -0
  21. data/lib/steep_kit/mixin_inference.rb +149 -0
  22. data/lib/steep_kit/output_plan.rb +181 -0
  23. data/lib/steep_kit/passes.rb +282 -0
  24. data/lib/steep_kit/patch_guard.rb +18 -0
  25. data/lib/steep_kit/paths.rb +17 -0
  26. data/lib/steep_kit/project.rb +44 -0
  27. data/lib/steep_kit/project_types.rb +72 -0
  28. data/lib/steep_kit/rbs_builder.rb +141 -0
  29. data/lib/steep_kit/rbs_collection.rb +61 -0
  30. data/lib/steep_kit/rbs_rails_postprocess.rb +98 -0
  31. data/lib/steep_kit/rbs_rails_regen.rb +39 -0
  32. data/lib/steep_kit/rbs_rails_scratch.rb +169 -0
  33. data/lib/steep_kit/rbs_rails_tasks.rb +20 -0
  34. data/lib/steep_kit/runtime.rb +344 -0
  35. data/lib/steep_kit/settings.rb +96 -0
  36. data/lib/steep_kit/signature_index.rb +116 -0
  37. data/lib/steep_kit/signature_kinds.rb +68 -0
  38. data/lib/steep_kit/signature_merger.rb +149 -0
  39. data/lib/steep_kit/signature_only.rb +33 -0
  40. data/lib/steep_kit/source_analysis.rb +227 -0
  41. data/lib/steep_kit/source_cache.rb +92 -0
  42. data/lib/steep_kit/source_files.rb +66 -0
  43. data/lib/steep_kit/source_set.rb +62 -0
  44. data/lib/steep_kit/steep.rb +35 -0
  45. data/lib/steep_kit/type_name_resolver.rb +47 -0
  46. data/lib/steep_kit/value_classes.rb +89 -0
  47. data/lib/steep_kit/version.rb +3 -0
  48. data/lib/steep_kit/watch.rb +64 -0
  49. data/lib/steep_kit/workspace_graph.rb +90 -0
  50. data/lib/steep_kit.rb +31 -0
  51. metadata +137 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d337350e62ef0f479b6bd12a50dc5d8002bf235372f0c5be947408881c4a671
4
+ data.tar.gz: 4dd26108010daa22cfa8f165e68819504ee19269889e33f9515324a2de5c7576
5
+ SHA512:
6
+ metadata.gz: 0c9c7fe15a67aadfe4544c2ad7ee604b22f6a036e0bdd0cf74c6db4ba1da5c8fb824009cbccb3e1d76f622f7c2bd5f85b87c10138a3f966f4bd59deb2208b6fe
7
+ data.tar.gz: 5735bfa5cf1f49cd8f5f5772032a064f14f84bfcb7aa9072435f0fefeabc02a4373b41da2872c273b25274d48540e86794092e30da317221521b2869d10843c3
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-29)
4
+
5
+ Initial public release:
6
+
7
+ - Inline RBS projection (`steep-kit generate` / `watch`) for `Data.define` / `Struct.new` value classes, class-body
8
+ `alias` / `alias_method`, and opt-in `attr_json` accessors.
9
+ - In-memory literal and record-hash constant inference, value-class superclasses, configurable dynamic superclasses, and
10
+ opt-in declarative mixin contracts (`mixins.class_methods`, `mixins.aliases`, `mixins.nested_classes`).
11
+ - Pre-push / CI gate (`steep-kit`): frozen `rbs_collection` check, inline grammar lint (including configured required
12
+ method-type checks), Rubydex-backed record-constant key lint, and `sig/projected` freshness check.
13
+ - Guarded Steep performance and memory optimizations (`signature_only_donors`, `index_signatures`,
14
+ `compact_completed_typing`) configured via `SteepKit::Steep.setup`.
15
+ - `steep-kit fast` wrapper for fast `--validate=skip` body checks with strict path/glob validation.
16
+ - Optional `rbs_rails` scratch-database regeneration (`db/schema.rb` and `db/structure.sql`) and standalone ActiveRecord
17
+ `SteepKit::RbsRailsPostprocess`.
18
+ - Optional `SteepKit::Runtime` (`require 'steep_kit/runtime'`) for runtime inline-RBS verification in test suites.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mike Eirih
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,396 @@
1
+ # SteepKit
2
+
3
+ Companion toolkit for Ruby applications and gems typed with **inline RBS** (`# @rbs` / `#:`) and checked by **Steep**.
4
+
5
+ The native RBS inline parser reads comments directly from Ruby files, but cannot see what Ruby defines at runtime:
6
+ `Data.define` and `Struct.new` members, class-body `alias` / `alias_method`, unannotated literal constants,
7
+ `ActiveSupport::Concern`-style `ClassMethods` extensions, dynamic superclasses, or macros such as `attr_json`.
8
+ Meanwhile, large repositories adopting Steep incrementally run into silent-donor overhead, high CLI/LSP memory
9
+ retention, drifted `rbs_rails` schemas, and runtime/signature drift.
10
+
11
+ `steep-kit` closes those gaps in four places:
12
+
13
+ 1. **Projected classic RBS (`sig/projected`)** for runtime definitions that need reopenings (`Data.define` / `Struct.new`,
14
+ `alias` / `alias_method`, and opt-in `attr_json`), with incremental `watch` support.
15
+ 2. **In-memory RBS & Steep enhancements** loaded from your `Steepfile` via `SteepKit::Steep.setup`: literal/record
16
+ constant inference, value-class and dynamic superclasses, opt-in mixin runtime contracts, plus Steep performance and
17
+ memory optimizations (signature-only donor groups, path-indexed signature lookups, completed-typing compaction).
18
+ 3. **A single pre-push / CI gate (`steep-kit`)** that keeps `rbs_collection` installed from its lockfile, lints inline
19
+ grammar pitfalls, checks every literal key access against record-typed constants across the whole workspace with
20
+ Rubydex, and enforces `sig/projected` freshness.
21
+ 4. **Optional developer tooling**: `steep-kit fast` for targeted Steep body checks, deterministic scratch-DB
22
+ `rbs_rails` regeneration and ActiveRecord post-processing, and `SteepKit::Runtime` for runtime RBS verification in
23
+ test suites.
24
+
25
+ Every opinionated or framework-specific convention is **off by default** and enabled explicitly in configuration.
26
+
27
+ ## Installation
28
+
29
+ Add `steep-kit` to a dedicated Gemfile group (excluded from production images via `BUNDLE_WITHOUT`):
30
+
31
+ ```ruby
32
+ group :typecheck do
33
+ gem 'steep-kit', require: false
34
+ gem 'steep', require: false # Steepfile integration & `steep-kit fast`
35
+ gem 'listen', require: false # optional: `steep-kit watch`
36
+ gem 'rbs_rails', require: false # optional: `steep-kit rbs-rails`
37
+ end
38
+ ```
39
+
40
+ Requires **Ruby 3.3+**. Runtime dependencies are `prism`, `rbs (~> 4.2.0)`, and `rubydex (~> 0.4.0)`.
41
+
42
+ ## Quickstart
43
+
44
+ ### 1. Create a config file
45
+
46
+ `steep-kit` looks for `.steep-kit.yml` (ideal for gems), `config/steep_kit.yml`, or `config/steep-kit.yml`:
47
+
48
+ ```yaml
49
+ # .steep-kit.yml
50
+ signature_paths:
51
+ - lib
52
+ ```
53
+
54
+ For an application adopting Steep incrementally, split `signature_paths` into fully diagnosed `checked_paths` and
55
+ silent donor paths (anything in `signature_paths` not covered by `checked_paths`):
56
+
57
+ ```yaml
58
+ # config/steep_kit.yml
59
+ signature_paths:
60
+ - app/constants
61
+ - app/models
62
+ - app/actions
63
+
64
+ checked_paths:
65
+ - app/constants
66
+ - app/actions
67
+ ```
68
+
69
+ When `checked_paths` is omitted, it defaults to `signature_paths`.
70
+
71
+ ### 2. Wire your `Steepfile`
72
+
73
+ ```ruby
74
+ require 'steep_kit/steep'
75
+
76
+ STEEP_KIT = SteepKit::Steep.setup(root: __dir__)
77
+
78
+ target :app do
79
+ implicitly_returns_nil!
80
+
81
+ signature 'sig/handwritten'
82
+ signature 'sig/rbs_rails'
83
+ signature STEEP_KIT.projected_root
84
+
85
+ STEEP_KIT.checked_paths.each { |path| check path, inline: true }
86
+
87
+ if STEEP_KIT.donor_paths.any?
88
+ group :donors do
89
+ STEEP_KIT.donor_paths.each { |path| check path, inline: true }
90
+ STEEP_KIT.checked_paths.each { |path| ignore path, inline: true }
91
+
92
+ configure_code_diagnostics(Steep::Diagnostic::Ruby.silent)
93
+ end
94
+ end
95
+ end
96
+ ```
97
+
98
+ `SteepKit::Steep.setup` pins `Encoding.default_external` to UTF-8 (preventing crashes on non-ASCII bytes under POSIX
99
+ locales), loads your config, registers active conventions, and installs only the enabled Steep patches.
100
+
101
+ ### 3. Run the gate and Steep
102
+
103
+ ```sh
104
+ bundle exec steep-kit generate # write sig/projected
105
+ bundle exec steep-kit # run the gate
106
+ bundle exec steep check # full Steep signature + body check
107
+ ```
108
+
109
+ ## CLI Commands
110
+
111
+ Run from the repository root:
112
+
113
+ ```sh
114
+ bundle exec steep-kit # run enabled gate stages
115
+ bundle exec steep-kit generate # write projected RBS files
116
+ bundle exec steep-kit watch # regenerate projections on file changes
117
+ bundle exec steep-kit fast [--group=NAME] [-j N] ... # fast body check (--validate=skip)
118
+ bundle exec steep-kit rbs-rails [Model ...] # regenerate sig/rbs_rails via scratch DB
119
+ bundle exec steep-kit --version # print version
120
+ ```
121
+
122
+ - **`steep-kit` (the gate):** runs enabled stages over one shared parse and stops on the first failure:
123
+ 1. `rbs-collection` — checks `rbs_collection.lock.yaml` availability and installs from the lockfile if missing (skipped automatically when `rbs_collection.yaml` is absent).
124
+ 2. `lint-inline` — reports native inline parser diagnostics plus inline grammar pitfalls (`SingletonClassDef`, `SingletonClassMember`, `ValueClassBlockDef`, and configured `RequiredMethodType` rules).
125
+ 3. `lint-constant-access` — indexes the workspace with Rubydex and verifies every literal `[]` / `fetch` symbol key on record-typed constants (including one-hop constant aliases), even outside `checked_paths`.
126
+ 4. `sig/projected` freshness — fails with changed, missing, and stale paths if the committed tree differs from `generate`.
127
+ - **`steep-kit fast`:** runs `steep check --no-daemon --validate=skip` for rapid feedback on Ruby bodies. Rejects bare directories with a glob hint and fails if a pattern selects zero Ruby bodies (instead of silently passing). Defaults to `STEEP_JOBS` (or `2`) workers and `steep.fast_group` if configured.
128
+
129
+ ## Default Behavior (Standard Ruby)
130
+
131
+ These behaviors are enabled by default and require no convention config:
132
+
133
+ ### Value classes (`Data.define` / `Struct.new`)
134
+
135
+ - `class Price < Data.define(:amount, :currency)` and `class Row < Struct.new(:key)` are parsed as `< ::Data` and
136
+ `< ::Struct[untyped]` without `NonConstantSuperClassName`.
137
+ - `Guest = Data.define(:name, :email)` inside a class or module body projects `class Guest < ::Data` (and suppresses
138
+ the colliding constant declaration).
139
+ - Splatted member arrays (`*FIELDS`) resolve lexically from symbol-array constants in the file.
140
+ - A typed `#initialize` in the class body or any reopening types the projected readers/accessors and `self.new`.
141
+ - Explicit member definitions and explicit `def self.new` are never overwritten.
142
+ - `lint-inline` flags `def` inside `Data.define(...) { ... }` / `Struct.new(...) { ... }` blocks (`[ValueClassBlockDef]`),
143
+ since RBS inline neither types nor checks those methods.
144
+
145
+ ### Class-body aliases (`alias` / `alias_method`)
146
+
147
+ - Class-body `alias new_name old_name` and `alias_method :new_name, :old_name` are projected into `sig/projected`.
148
+ - Place `# @rbs skip` above an alias whose target is dynamic (`delegate`, `define_method`) to skip projection without
149
+ triggering `UnusedInlineAnnotation`.
150
+
151
+ ### Literal & record constant inference
152
+
153
+ Unannotated pure-literal constants are typed in memory for Steep, LSP, and `lint-constant-access`:
154
+
155
+ ```ruby
156
+ module Billing
157
+ CURRENCIES = %w[EUR USD].freeze # ::Array[::String]
158
+ FEES = { card: 0.014, invoice: 29 } # { card: ::Float, invoice: ::Integer }
159
+ LIMITS = (1..30) # ::Range[::Integer]
160
+ FALLBACK = FEES # { card: ::Float, invoice: ::Integer }
161
+ end
162
+ ```
163
+
164
+ - Symbol-keyed hash literals become RBS **records**, so `FEES[:card]` stays non-nil under `implicitly_returns_nil!` and
165
+ unknown literal keys (`FEES[:cash]`) fail `lint-constant-access` across the entire workspace.
166
+ - Sibling constant references and trailing `#:` annotations (with absolute type names inside namespaces) resolve
167
+ lexically to a fixed point; cycles stay `untyped`.
168
+ - An explicit trailing `#:` annotation always wins.
169
+
170
+ ### Inline grammar lint (`lint-inline`)
171
+
172
+ - **`[SingletonClassDef]` / `[SingletonClassMember]`:** RBS inline misfiles declarations inside `class << self` as
173
+ instance members or constants of the enclosing class. Write `def self.name`, and move attributes/mixins/constants out
174
+ or mark them `# @rbs skip`.
175
+ - **`[ValueClassBlockDef]`:** move methods out of `Data.define`/`Struct.new` blocks into a `class Name < Data.define(...)` body.
176
+
177
+ ### Steep performance & memory optimizations
178
+
179
+ Enabled by default via `SteepKit::Steep.setup` (each individually opt-outable under `steep:`):
180
+
181
+ - **`signature_only_donors`:** groups configured with `Steep::Diagnostic::Ruby.silent` are validated as signatures only
182
+ during CLI `steep check`, avoiding wasted body type-checking on donor files.
183
+ - **`index_signatures`:** indexes `RBS::Environment` sources, constants, and globals by path (avoiding repeated linear
184
+ scans) and reuses `factory.type_name_resolver` across validators and type assertions.
185
+ - **`compact_completed_typing`:** compacts finished `Steep::Typing` graphs to diagnostics, call counts, and (in editor
186
+ LSP processes) source indexes, preventing old environments from being retained in memory.
187
+
188
+ Every Steep patch checks that the expected Steep methods exist before prepending; if an unsupported Steep version
189
+ changes internals, `steep-kit` skips the patch with a warning instead of crashing.
190
+
191
+ ---
192
+
193
+ ## Formalized Conventions (Opt-in Settings)
194
+
195
+ All architecture, macro, and framework conventions below are **disabled / empty by default**. Enable only what your
196
+ project uses.
197
+
198
+ ### 1. Third-party macro projections (`projections:`)
199
+
200
+ ```yaml
201
+ projections:
202
+ data_structs: true # default: true
203
+ aliases: true # default: true
204
+ attr_json: true # default: false — opt-in
205
+ ```
206
+
207
+ When `attr_json: true` is enabled, `attr_json` declarations project typed readers, writers, and boolean predicates:
208
+
209
+ - `:string` / `:text` -> `::String`, `:integer` / `:big_integer` -> `::Integer`, `:float` -> `::Float`,
210
+ `:boolean` -> `bool`, `:datetime` -> `::ActiveSupport::TimeWithZone`, `:date` -> `::Date`,
211
+ `:decimal` -> `::BigDecimal`, `Model.to_type` -> `Model`; anything else -> `untyped`.
212
+ - Readers are nilable unless `default:` is non-nil or `array: true` (which defaults to `[]`).
213
+ - Boolean predicates (`flag?`) are emitted except inside `AttrJson::Model`, which defines none.
214
+
215
+ ### 2. Mixin runtime contracts (`mixins:`)
216
+
217
+ Many Ruby patterns dynamically install class methods, aliases, or nested classes when a module is included or a base
218
+ class is inherited. `mixins:` lets you declare those contracts so Steep sees them in memory without committing
219
+ boilerplate reopenings.
220
+
221
+ #### `mixins.class_methods` — `ActiveSupport::Concern` / `ClassMethods` convention
222
+
223
+ ```yaml
224
+ mixins:
225
+ class_methods:
226
+ - Lockable # `include Lockable` -> `extend ::Lockable::ClassMethods`
227
+ - { include: Trackable, extend: Trackable::DSL } # explicit class-methods module name
228
+ ```
229
+
230
+ Whenever a class or module includes the named mixin (and does not already explicitly `extend` it), Steep sees the
231
+ corresponding `extend` declaration.
232
+
233
+ #### `mixins.aliases` — command / operation alias convention
234
+
235
+ ```yaml
236
+ mixins:
237
+ aliases:
238
+ - on: Operations::Base
239
+ alias: call!
240
+ to: call
241
+ require_typed: true
242
+ ```
243
+
244
+ - Matches any class or module that `include`s `on`, or any class that inherits from `on` (relative names resolve
245
+ lexically in the enclosing namespace).
246
+ - Infers `alias call! call` in memory unless the class defines `call!` itself, so `call!` automatically inherits the
247
+ exact inline signature of `#call`.
248
+ - When `require_typed: true`, `lint-inline` reports `[RequiredMethodType]` whenever a matching class defines `#call`
249
+ without an inline type annotation.
250
+
251
+ #### `mixins.nested_classes` — generated nested class convention (e.g. async workers)
252
+
253
+ ```yaml
254
+ mixins:
255
+ nested_classes:
256
+ - on: Operations::Async
257
+ name: Worker
258
+ include:
259
+ - Sidekiq::Job
260
+ extend:
261
+ - Sidekiq::Job::ClassMethods
262
+ - on: Custom::Async
263
+ name: Worker
264
+ superclass: Custom::Async::Job
265
+ ```
266
+
267
+ - When a class includes (or inherits from) `on`, Steep sees a nested `class Worker` with the configured superclass,
268
+ `include`s, and `extend`s.
269
+ - An explicit `class Worker` in the source merges cleanly with the inferred superclass/mixins; an explicit `Worker`
270
+ constant or class alias is left untouched.
271
+
272
+ ### 3. Dynamic superclasses (`superclasses:`)
273
+
274
+ ```yaml
275
+ superclasses:
276
+ Engine.record_base: ApplicationRecord
277
+ ```
278
+
279
+ Maps a superclass expression written as a method call (`class Entry < Engine.record_base`) to the constant class it
280
+ returns, avoiding `NonConstantSuperClassName` diagnostics while keeping the class body typed.
281
+
282
+ ### 4. Gate & Steep settings (`checks:`, `steep:`, `projected_root:`)
283
+
284
+ ```yaml
285
+ projected_root: sig/projected # default: sig/projected
286
+
287
+ checks:
288
+ rbs_collection: true # default: true
289
+ lint_inline: true # default: true
290
+ lint_constant_access: true # default: true
291
+ projected_freshness: true # default: true
292
+
293
+ steep:
294
+ literal_constants: true # default: true
295
+ value_classes: true # default: true
296
+ alias_skip: true # default: true
297
+ signature_only_donors: true # default: true
298
+ index_signatures: true # default: true
299
+ compact_completed_typing: true # default: true
300
+ fast_group: app # default: nil (optional default `--group` for `steep-kit fast`)
301
+ ```
302
+
303
+ ### 5. Optional `rbs_rails` integration (`rbs_rails:`)
304
+
305
+ `steep-kit rbs-rails [Model ...]` regenerates `sig/rbs_rails` deterministically from your committed schema
306
+ (`db/schema.rb` or `db/structure.sql`) using a purged scratch database rather than a drifted development database.
307
+
308
+ In a Rails app, require the rake task (rescued for production bundles that exclude `:typecheck`):
309
+
310
+ ```ruby
311
+ # lib/tasks/rbs.rake
312
+ begin
313
+ require 'steep_kit/rbs_rails_tasks'
314
+ rescue LoadError
315
+ # production images exclude the typecheck group
316
+ end
317
+ ```
318
+
319
+ Configure optional post-processing in `.steep-kit.yml` / `config/steep_kit.yml`:
320
+
321
+ ```yaml
322
+ rbs_rails:
323
+ postgres_arrays: true # default: true — wrap PG array columns in ::Array[T]
324
+ custom_type_rbs_type: true # default: true — honor #rbs_type on custom ActiveRecord::Type subclasses
325
+ pure_nilable_readers: true # default: true — annotate nilable attribute/association readers with %a{pure}
326
+ scratch_suffix: _rbs_scratch # default: _rbs_scratch
327
+ ```
328
+
329
+ - **Custom `#rbs_type` protocol:** if a custom `ActiveRecord::Type::Value` defines `def rbs_type = '::MyApp::PlainTime'`,
330
+ the post-processor rewrites the attribute's reader and writer while preserving column optionality.
331
+ - **`%a{pure}` trade-off (`pure_nilable_readers`):** marking nilable ActiveRecord column/association readers `%a{pure}`
332
+ allows Steep to narrow `record.user.name if record.user` without repetitive local assignments, assuming the attribute
333
+ is not mutated mid-branch. Set `pure_nilable_readers: false` if you prefer strict flow typing.
334
+ - **Non-Rails ActiveRecord apps (Hanami, Sinatra, engines):** `SteepKit::RbsRailsPostprocess` has zero Rails dependency
335
+ and can be called directly:
336
+
337
+ ```ruby
338
+ require 'steep_kit/rbs_rails_postprocess'
339
+
340
+ result = SteepKit::RbsRailsPostprocess.new(model).call(RbsRails::ActiveRecord.class_to_rbs(model))
341
+ ```
342
+
343
+ ---
344
+
345
+ ## Runtime Type Checking (`steep_kit/runtime`)
346
+
347
+ Verify your inline RBS signatures against real values during test runs using `RBS::Test::Tester`:
348
+
349
+ ```ruby
350
+ # spec/support/rbs_runtime.rb
351
+ require 'steep_kit/runtime'
352
+
353
+ SteepKit::Runtime.install(root: File.expand_path('../..', __dir__)) if ENV['RBS_RUNTIME']
354
+ ```
355
+
356
+ Run tests with:
357
+
358
+ ```sh
359
+ # Raise on first type mismatch (with recursive nested path diagnostics):
360
+ RBS_RUNTIME=1 RBS_TEST_TARGET='Billing::*' bundle exec rspec
361
+
362
+ # Or log all mismatches to JSONL without failing the suite:
363
+ RBS_RUNTIME=report RBS_TEST_TARGET='Billing::*' RBS_RUNTIME_LOG=tmp/rbs_runtime.jsonl bundle exec rspec
364
+ ```
365
+
366
+ What `SteepKit::Runtime` adds over raw `rbs/test`:
367
+
368
+ - Loads inline RBS from `signature_paths` alongside `sig/` directories automatically (override with `RBS_TEST_OPT`,
369
+ `signature_dirs:`, or `libraries:`).
370
+ - Pinpoints nested record, tuple, array, and hash mismatches (`return[:items][1]: expected ::String, given Integer 42`).
371
+ - Fixes prepended method-chain ownership, `ruby2_keywords` hash checks, and setter (`foo=`) return semantics.
372
+ - Automatically tolerates `RSpec::Mocks` doubles (configurable via `unchecked_classes:`), and when loaded, accepts
373
+ `ActiveSupport::TimeWithZone` as `::Time` and `ActiveRecord::Relation` / `CollectionProxy` covariantly.
374
+
375
+ ---
376
+
377
+ ## Compatibility
378
+
379
+ - Tested on **Ruby 3.3, 3.4, and 4.0**
380
+ - Tested against **RBS 4.2.x**, **Steep 2.1.x**, and **Rubydex 0.4.x**
381
+ - Inline parser patches target RBS 4.2 internals (pinned at `~> 4.2.0` in the gemspec). Steep patches are version-guarded
382
+ and individually disableable under `steep:`.
383
+
384
+ ## Development & Benchmarks
385
+
386
+ ```sh
387
+ bundle install
388
+ bundle exec rake # RSpec + RuboCop
389
+ bundle exec rake build # pkg/steep-kit-<version>.gem
390
+ ```
391
+
392
+ Reproducible host CPU, RSS, watch, and LSP retention benchmarks live in [bench/README.md](bench/README.md).
393
+
394
+ ## License
395
+
396
+ MIT License — originally authored by Mike Eirih. See [LICENSE.md](LICENSE.md).
data/exe/steep-kit ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Ruby sources and generated RBS are UTF-8; don't let a POSIX locale decide.
4
+ Encoding.default_external = Encoding::UTF_8
5
+
6
+ require 'steep_kit'
7
+
8
+ begin
9
+ exit SteepKit::CLI.new.run(ARGV)
10
+ rescue Interrupt
11
+ exit 130
12
+ end
@@ -0,0 +1,41 @@
1
+ require 'prism'
2
+ require 'rbs'
3
+ require_relative 'config'
4
+ require_relative 'value_classes'
5
+
6
+ module SteepKit
7
+ # The inline parser has no alias visitor: consume the Aliases pass's
8
+ # `# @rbs skip` above a class-body alias, or it is reported unused.
9
+ module AliasSkip
10
+ def self.install!
11
+ target = RBS::InlineParser::Parser
12
+ target.prepend(self) unless target.ancestors.include?(self)
13
+ end
14
+
15
+ # An alias has nothing else to visit.
16
+ def visit_alias_method_node(node)
17
+ skip_node?(node) if Config.steep_settings.alias_skip && class_body_statement?(node)
18
+ nil
19
+ end
20
+
21
+ def visit_call_node(node)
22
+ return if skip_alias_method?(node)
23
+
24
+ super
25
+ end
26
+
27
+ private
28
+
29
+ def skip_alias_method?(node)
30
+ Config.steep_settings.alias_skip && node.receiver.nil? && node.name == :alias_method && class_body_statement?(node) && skip_node?(node)
31
+ end
32
+
33
+ def class_body_statement?(node)
34
+ scope = current_module or return false
35
+
36
+ ValueClasses.statements(scope.node).any? { |statement| statement.equal?(node) }
37
+ end
38
+ end
39
+ end
40
+
41
+ SteepKit::AliasSkip.install!
@@ -0,0 +1,62 @@
1
+ require_relative 'lint_constant_access'
2
+ require_relative 'lint_inline'
3
+ require_relative 'output_plan'
4
+ require_relative 'project'
5
+ require_relative 'project_types'
6
+ require_relative 'rbs_collection'
7
+ require_relative 'signature_kinds'
8
+ require_relative 'source_files'
9
+
10
+ module SteepKit
11
+ # Default `steep-kit` gate: runs enabled stages over one shared parse and
12
+ # stops at the first failure.
13
+ class Check
14
+ def initialize(config:, stdout: $stdout, stderr: $stderr)
15
+ @config = config
16
+ @stdout = stdout
17
+ @stderr = stderr
18
+ end
19
+
20
+ def run
21
+ RbsCollection.new(root: @config.root, stdout: @stdout).run if checks.rbs_collection
22
+ return 0 unless source_checks_enabled?
23
+
24
+ analyses = SourceFiles.new(root: @config.root).analyses(@config.signature_paths)
25
+ return 1 if checks.lint_inline && !lint_passes?(analyses)
26
+ return 1 if checks.lint_constant_access && !constant_access_passes?(analyses)
27
+ return 1 if checks.projected_freshness && !projected_fresh?(analyses)
28
+
29
+ 0
30
+ end
31
+
32
+ private
33
+
34
+ def checks
35
+ @config.checks
36
+ end
37
+
38
+ def source_checks_enabled?
39
+ checks.lint_inline || checks.lint_constant_access || checks.projected_freshness
40
+ end
41
+
42
+ def lint_passes?(analyses)
43
+ LintInline.new(stdout: @stdout, stderr: @stderr).run(analyses).zero?
44
+ end
45
+
46
+ def constant_access_passes?(analyses)
47
+ LintConstantAccess.new(config: @config, stdout: @stdout, stderr: @stderr).run(analyses).zero?
48
+ end
49
+
50
+ def projected_fresh?(analyses)
51
+ kinds = SignatureKinds.new(root: @config.root, projected_root: @config.projected_root).call
52
+ project = Project.new(analyses, signature_kinds: kinds)
53
+ ProjectTypes.new(config: @config).call(check: true, project:)
54
+ @stdout.puts("#{@config.projected_root}: up to date")
55
+ true
56
+ rescue OutputPlan::StaleError => e
57
+ @stderr.puts(e.message)
58
+ @stderr.puts(' run `steep-kit generate` and commit the changes')
59
+ false
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,110 @@
1
+ require 'pathname'
2
+ require_relative 'check'
3
+ require_relative 'config'
4
+ require_relative 'error'
5
+ require_relative 'fast'
6
+ require_relative 'generate'
7
+ require_relative 'rbs_rails_regen'
8
+ require_relative 'version'
9
+ require_relative 'watch'
10
+
11
+ module SteepKit
12
+ class CLI
13
+ PROGRAM = 'steep-kit'.freeze
14
+
15
+ def initialize(root: Pathname.pwd, stdout: $stdout, stderr: $stderr)
16
+ @root = Pathname(root).expand_path
17
+ @stdout = stdout
18
+ @stderr = stderr
19
+ end
20
+
21
+ def run(argv)
22
+ case (@command = argv.shift)
23
+ when nil then check
24
+ when 'generate' then generate(argv)
25
+ when 'watch' then watch(argv)
26
+ when 'fast' then fast(argv)
27
+ when 'rbs-rails' then rbs_rails(argv)
28
+ when '-v', '--version' then version
29
+ when '-h', '--help' then help
30
+ else error("unknown command: #{@command}")
31
+ end
32
+ rescue Error => e
33
+ error(e.message)
34
+ end
35
+
36
+ private
37
+
38
+ def check
39
+ Check.new(config: Config.load(root: @root), stdout: @stdout, stderr: @stderr).run
40
+ end
41
+
42
+ def generate(argv)
43
+ return usage("#{PROGRAM} generate — write projected RBS files") if help?(argv)
44
+
45
+ reject_arguments!(argv)
46
+ config = Config.load(root: @root)
47
+ @stdout.puts("#{PROGRAM} generate: #{config.projected_root} #{Generate.new(config:).call}")
48
+ 0
49
+ end
50
+
51
+ def watch(argv)
52
+ return usage("#{PROGRAM} watch — regenerate projected RBS files on changes") if help?(argv)
53
+
54
+ reject_arguments!(argv)
55
+ Watch.new(config: Config.load(root: @root), stdout: @stdout, stderr: @stderr).run
56
+ 0
57
+ end
58
+
59
+ def fast(argv)
60
+ return usage("#{PROGRAM} fast [--group=NAME] [-j N] [path_or_glob ...] — check Ruby bodies with --validate=skip") if help?(argv)
61
+
62
+ config = Config.locate(root: @root) ? Config.load(root: @root) : nil
63
+ Fast.new(root: @root, config:, stdout: @stdout, stderr: @stderr).run(argv)
64
+ end
65
+
66
+ def rbs_rails(argv)
67
+ return usage("#{PROGRAM} rbs-rails [Model ...] — regenerate sig/rbs_rails from the schema via a scratch database") if help?(argv)
68
+
69
+ reject_options!(argv)
70
+ RbsRailsRegen.new(root: @root, models: argv).call
71
+ 0
72
+ end
73
+
74
+ def version
75
+ @stdout.puts("#{PROGRAM} #{VERSION}")
76
+ 0
77
+ end
78
+
79
+ def help?(argv)
80
+ argv.one? && %w[-h --help].include?(argv.first)
81
+ end
82
+
83
+ def usage(text)
84
+ @stdout.puts("Usage: #{text}")
85
+ 0
86
+ end
87
+
88
+ def reject_arguments!(argv)
89
+ reject_options!(argv)
90
+ raise Error, "invalid argument: #{argv.join(' ')}" if argv.any?
91
+ end
92
+
93
+ def reject_options!(argv)
94
+ options = argv.select { |argument| argument.start_with?('-') }
95
+ raise Error, "invalid option: #{options.join(' ')}" if options.any?
96
+ end
97
+
98
+ def help
99
+ @stdout.puts("Usage: #{PROGRAM} [generate | watch | fast [options] [paths...] | rbs-rails [Model ...]]")
100
+ @stdout.puts(' no command: run enabled gate checks (RBS collection, inline lint, record keys, projected freshness)')
101
+ 0
102
+ end
103
+
104
+ def error(message)
105
+ prefix = [PROGRAM, @command].compact.join(' ')
106
+ @stderr.puts("#{prefix}: #{message}")
107
+ 1
108
+ end
109
+ end
110
+ end