Skip to content

feat(cli): add generator configuration command - #4265

Merged
codeshaunted merged 1 commit into
canaryfrom
codex/generate-add
Jul 29, 2026
Merged

codeshaunted merged 1 commit into
canaryfrom
codex/generate-add

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • add baml generate add <output-type> as a real CLI subcommand
  • create the first available [generator.clientN] entry while preserving TOML comments and formatting
  • derive generator defaults from OutputType and expose every supported bridge name
  • add baml generate add guidance to newly initialized baml.toml files
  • remove the redundant clap update pass that prevented optional nested subcommands

Testing

  • cargo test -p baml_cli --lib
  • cargo test -p baml_cli generate
  • cargo clippy -p baml_cli -p baml_codegen_types --tests -- -D warnings
  • cargo fmt --all -- --check
  • manually tested baml init followed by baml generate add python/pydantic2

Additional Notes

The Go target requires --sdk-import-path; target-specific naming defaults are centralized in From<OutputType> for Generator.

Summary by CodeRabbit

  • New Features
    • Added baml generate add to configure a client generator directly in baml.toml.
    • Supports all available output targets, including Python, TypeScript, Go, Rust, Java, C++, C#, and Swift.
    • Automatically selects the next available client configuration and preserves existing TOML formatting and comments.
    • Added validation and support for Go SDK import paths.
  • Documentation
    • Updated project initialization guidance with instructions for adding and running generators.

@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 28, 2026 11:44pm
promptfiddle Ready Ready Preview, Comment Jul 28, 2026 11:44pm
promptfiddle2 Ready Ready Preview, Comment Jul 28, 2026 11:44pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – beps July 28, 2026 23:22 Inactive
@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Generator CLI

Layer / File(s) Summary
Generator metadata contract
baml_language/crates/baml_codegen_types/src/generator_fields.rs
Adds output-type enumeration helpers and manifest-ready generator defaults.
Generator installation flow
baml_language/crates/baml_cli/Cargo.toml, baml_language/crates/baml_cli/src/generate.rs
Adds generate add, validates arguments and projects, inserts the first available clientN generator entry, and writes baml.toml.
CLI parsing and starter guidance
baml_language/crates/baml_cli/src/commands.rs, baml_language/crates/baml_cli/src/init_command.rs
Updates smart parsing, adds CLI coverage, and replaces starter generator comments with generate add instructions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant GenerateArgs
  participant AddGeneratorArgs
  participant baml.toml
  User->>GenerateArgs: generate add OUTPUT_TYPE
  GenerateArgs->>AddGeneratorArgs: dispatch add command
  AddGeneratorArgs->>baml.toml: insert generator.clientN
  baml.toml-->>AddGeneratorArgs: updated manifest
  AddGeneratorArgs-->>User: report completion
Loading

Possibly related PRs

Suggested reviewers: hellovai

Poem

A rabbit adds a client with care,
Leaves every comment resting there.
Python, Go, and targets bright,
Join the manifest overnight.
generate add hops into sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: a new CLI command for adding generator configuration.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/generate-add

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 28, 2026 23:30 Inactive
@github-actions

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 27.3 MB 11.6 MB file 27.3 MB +31.4 KB (+0.1%) OK
✅ packed-program Linux 🔒 17.7 MB 7.3 MB file 17.7 MB +12.3 KB (+0.1%) OK
✅ baml-cli macOS 🔒 21.2 MB 10.2 MB file 21.2 MB +16.6 KB (+0.1%) OK
✅ packed-program macOS 🔒 13.9 MB 6.4 MB file 13.9 MB +16 B (+0.0%) OK
✅ baml-cli Windows 🔒 22.9 MB 10.4 MB file 22.9 MB +16.9 KB (+0.1%) OK
✅ packed-program Windows 🔒 14.8 MB 6.5 MB file 14.8 MB +2.6 KB (+0.0%) OK
✅ bridge_wasm WASM 16.6 MB 🔒 4.5 MB gzip 4.5 MB +9.0 KB (+0.2%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
baml_language/crates/baml_cli/src/generate.rs (2)

47-59: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider exposing --output-dir on baml generate add.

Generator.output_dir and add_generator_to_manifest (Line 169) already support writing an output_dir value, but AddGeneratorArgs has no corresponding CLI flag, so every generator added via this command always defaults to .. + generated_directory() in discover_generators. Users needing a custom layout must hand-edit baml.toml afterward.

♻️ Suggested addition
 pub struct AddGeneratorArgs {
     #[arg(value_name = "OUTPUT_TYPE", value_parser = add_output_type_parser())]
     pub output_type: OutputType,

     /// Project search starting point. Defaults to the current directory.
     #[arg(long, value_name = "PATH")]
     pub from: Option<PathBuf>,

+    /// Output directory override, written to the generator's `output_dir`.
+    #[arg(long, value_name = "PATH")]
+    pub output_dir: Option<String>,
+
     /// Go module import path for the generated baml_sdk package.
     #[arg(long, value_name = "IMPORT_PATH")]
     pub sdk_import_path: Option<String>,
 }

And in run(): generator.output_dir = self.output_dir.clone();

Also applies to: 90-124, 169-171

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_cli/src/generate.rs` around lines 47 - 59, Add an
optional output_dir PathBuf field with a --output-dir argument to
AddGeneratorArgs, then propagate it in run() by assigning the parsed value to
generator.output_dir before add_generator_to_manifest. Preserve existing default
behavior when the flag is omitted and ensure the value reaches the
manifest-writing flow.

855-885: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a Go happy-path test through AddGeneratorArgs::run().

The Go-specific validation branch in run() (Lines 97-111) is only unit-tested indirectly — add_go_generator_writes_required_import_path builds the Generator/manifest directly, bypassing run()'s own match logic. Consider adding a variant of add_command_updates_project_manifest with output_type: OutputType::Go and a valid sdk_import_path to cover the actual CLI entry point end-to-end.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_cli/src/generate.rs` around lines 855 - 885, The
existing add_command_updates_project_manifest test only exercises the TypeScript
path; add a parallel happy-path test that invokes AddGeneratorArgs::run() with
OutputType::Go and a valid sdk_import_path, then assert success and verify the
generated manifest contains the expected Go output type and import path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@baml_language/crates/baml_cli/src/generate.rs`:
- Around line 47-59: Add an optional output_dir PathBuf field with a
--output-dir argument to AddGeneratorArgs, then propagate it in run() by
assigning the parsed value to generator.output_dir before
add_generator_to_manifest. Preserve existing default behavior when the flag is
omitted and ensure the value reaches the manifest-writing flow.
- Around line 855-885: The existing add_command_updates_project_manifest test
only exercises the TypeScript path; add a parallel happy-path test that invokes
AddGeneratorArgs::run() with OutputType::Go and a valid sdk_import_path, then
assert success and verify the generated manifest contains the expected Go output
type and import path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8878a961-2466-44d8-a2a0-a37ef561a4f5

📥 Commits

Reviewing files that changed from the base of the PR and between 6fc97e5 and bc587a5.

⛔ Files ignored due to path filters (1)
  • baml_language/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • baml_language/crates/baml_cli/Cargo.toml
  • baml_language/crates/baml_cli/src/commands.rs
  • baml_language/crates/baml_cli/src/generate.rs
  • baml_language/crates/baml_cli/src/init_command.rs
  • baml_language/crates/baml_codegen_types/src/generator_fields.rs

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle July 28, 2026 23:44 Inactive
@codeshaunted
codeshaunted added this pull request to the merge queue Jul 29, 2026
Merged via the queue into canary with commit 8c8af41 Jul 29, 2026
83 checks passed
@codeshaunted
codeshaunted deleted the codex/generate-add branch July 29, 2026 00:13

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — bc587a58 Deployed Jul 28, 2026 by vercel[bot]
Preview – promptfiddle2 — bc587a58 Deployed Jul 28, 2026 by vercel[bot]
Preview – beps — bc587a58 Deployed Jul 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant