Skip to content

lex-codegen

Code generation engine for LegionIO extensions. Scaffolds complete lex-* gem trees from scratch, renders individual ERB templates, validates existing extension structure, and generates companion RSpec files. Used by the legion lex create CLI command and by agentic swarm pipelines.

Installation

Add to your Gemfile or gemspec:

gem'lex-codegen'

Or install directly:

gem install lex-codegen

Usage

Scaffold a complete extension

require'legion/extensions/codegen'client=Legion::Extensions::Codegen::Client.new(base_path: '/path/to/output')result=client.scaffold_extension(name: 'myextension',module_name: 'Myextension',description: 'Does something useful',helpers: ['config'],runner_methods: [{name: 'run_job',params: ['job_id:']},{name: 'check_status',params: ['job_id:','verbose: false']}])result[:success]# => trueresult[:path]# => '/path/to/output/lex-myextension'result[:files_created]# => 15

This writes a fully structured gem including gemspec, Gemfile, .rubocop.yml, GitHub Actions CI workflow, .rspec, .gitignore, LICENSE, version.rb, entry point, client, helpers, runners, and RSpec files for all of the above.

Generate a single file

result=client.generate_file(template_type: :runner,output_path: '/tmp/myrunner.rb',variables: {module_name: 'Myextension',gem_name_underscored: 'myextension',runner_class: 'RunJob',methods: [{name: 'run_job',params: ['job_id:']}]})result[:bytes]# => number of bytes written

Render a template to a string (without writing to disk)

runner=Legion::Extensions::Codegen::Runners::Templatecontent=runner.render_template(template_type: :version,variables: {module_name: 'Myextension',gem_version: '0.1.0'})putscontent[:content]# frozen_string_literal: true# module Legion::Extensions::Myextension; VERSION = '0.1.0'; end

List available templates

runner.list_templates# => { success: true, templates: [:gemspec, :gemfile, :rubocop, :ci, :rspec, :gitignore,# :license, :version, :entry_point, :spec_helper, :runner, :client] }

Inspect required variables for a template

runner.template_variables(template_type: :gemspec)# => { success: true, template_type: :gemspec,# required_variables: [:gem_name, :module_name, :description, :author, :email,# :ruby_version, :license, :extra_deps] }

Validate an existing extension

validator=Legion::Extensions::Codegen::Runners::Validate# Check directory structurevalidator.validate_structure(path: '/path/to/lex-myextension')# => { valid: true, missing: [], present: ['Gemfile', '.rubocop.yml', ...] }# Check rubocop configvalidator.validate_rubocop_config(path: '/path/to/lex-myextension')# => { valid: true, issues: [] }# Check gemspec fieldsvalidator.validate_gemspec(path: '/path/to/lex-myextension')# => { valid: true, issues: [], path: '/path/to/lex-myextension/lex-myextension.gemspec' }

Generate spec files directly

spec_gen=Legion::Extensions::Codegen::Helpers::SpecGenerator.new# Runner specputsspec_gen.generate_runner_spec(module_name: 'Myextension',runner_name: 'run_job',methods: [{name: 'run_job',params: ['job_id:']}])# Client specputsspec_gen.generate_client_spec(module_name: 'Myextension')# Helper specputsspec_gen.generate_helper_spec(module_name: 'Myextension',helper_name: 'config',methods: [{name: 'load',params: []}])

Available Templates

TemplateGenerates
gemspeclex-name.gemspec
gemfileGemfile with gemspec + test group
rubocop.rubocop.yml with LegionIO defaults
ci.github/workflows/ci.yml (calls shared reusable workflow)
rspec.rspec with --format documentation
gitignore.gitignore with standard Ruby entries
licenseLICENSE (MIT)
versionlib/legion/extensions/<name>/version.rb
entry_pointlib/legion/extensions/<name>.rb
spec_helperspec/spec_helper.rb with Legion::Logging stub
runnerOne runner module with stubbed methods
clientClient class including runner modules

Defaults

SettingDefault
Ruby version3.4
LicenseMIT
AuthorEsity
Emailmatthewdiverson@gmail.com
Gem version0.1.0

Development

bundle install
bundle exec rspec
bundle exec rubocop

License

MIT. See LICENSE.

About

Code generation engine for LegionIO extensions

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages