feat(cli): add agent-friendly diagnostic output - #4127
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe CLI centralizes output configuration through presets and environment-backed overrides, supports agent-formatted diagnostics, routes command diagnostics through the resolved policy, and tracks color and hyperlinks independently. ChangesCLI output and diagnostics
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant RuntimeCli
participant output_init
participant Painter
participant render_diagnostics
RuntimeCli->>output_init: init(OutputArgs)
output_init->>Painter: install stream color state
Painter->>output_init: query stream color and hyperlink policy
render_diagnostics->>output_init: obtain diagnostic render configuration
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
Binary size checks passed✅ 7 passed
Generated by |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
baml_language/crates/baml_cli/src/output.rs (1)
232-246: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winGeneric agent env-var names risk false-positive auto-detection.
AGENT_ENV_VARSincludes bare names like"AGENT"and"AI_AGENT", which are plausible generic environment variable names unrelated to coding agents (e.g., set by unrelated CI/build-agent tooling or user scripts). A false positive here silently switchesOutputPreset::Autoto the no-color/no-hyperlink Agent preset for ordinary human/CI runs, which is subtle to diagnose since it's controlled entirely by ambient environment rather than an explicit flag.Consider requiring one of the more specific/product-scoped vars, or at least documenting the false-positive risk so downstream users know
--output-preset humanoverrides it.🤖 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/output.rs` around lines 232 - 246, Update AGENT_ENV_VARS and running_in_agent so auto-detection relies only on specific coding-agent or product-scoped environment variables, removing generic names such as AGENT and AI_AGENT. Preserve explicit --output-preset human override behavior and the existing truthy-variable detection.baml_language/crates/baml_compiler_diagnostics/src/render.rs (1)
497-561: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider caching
shortest_unique_pathper render batch.
shortest_unique_pathis recomputed from scratch (iterating the wholefile_pathsmap per path-component) for every span, with no memoization across arender_diagnosticscall — unlike theAriadnepath in the same function, which explicitly hoistsSourceCacheconstruction out of the loop specifically to avoid "a large fraction ofbaml checkwall time" on warning-heavy projects (per the comment onrender_diagnostics, lines 219-227). For large multi-file projects with many diagnostics/annotations, this repeats an O(files × path-depth) computation per span.Consider threading a small
HashMap<FileId, String>cache throughrender_agent/render_diagnostics(mirroring theSourceCachepattern) to compute each file's disambiguated suffix once per batch.🤖 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_compiler_diagnostics/src/render.rs` around lines 497 - 561, Cache the result of shortest_unique_path once per render batch instead of recomputing it for every span. Thread a HashMap<FileId, String> through render_diagnostics and render_agent, populate it on first use, and have format_span reuse the cached path while preserving the existing fallback and disambiguation behavior.
🤖 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/output.rs`:
- Around line 232-246: Update AGENT_ENV_VARS and running_in_agent so
auto-detection relies only on specific coding-agent or product-scoped
environment variables, removing generic names such as AGENT and AI_AGENT.
Preserve explicit --output-preset human override behavior and the existing
truthy-variable detection.
In `@baml_language/crates/baml_compiler_diagnostics/src/render.rs`:
- Around line 497-561: Cache the result of shortest_unique_path once per render
batch instead of recomputing it for every span. Thread a HashMap<FileId, String>
through render_diagnostics and render_agent, populate it on first use, and have
format_span reuse the cached path while preserving the existing fallback and
disambiguation behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 696ca694-88c2-4373-86f4-550ca09002df
📒 Files selected for processing (10)
baml_language/crates/baml_cli/Cargo.tomlbaml_language/crates/baml_cli/src/check_command.rsbaml_language/crates/baml_cli/src/commands.rsbaml_language/crates/baml_cli/src/diagnostics_cache.rsbaml_language/crates/baml_cli/src/generate.rsbaml_language/crates/baml_cli/src/lib.rsbaml_language/crates/baml_cli/src/output.rsbaml_language/crates/baml_cli/src/pack_command.rsbaml_language/crates/baml_cli/src/paint.rsbaml_language/crates/baml_compiler_diagnostics/src/render.rs
Summary
Example
Configuration
Tests
Linear: B-407
Summary by CodeRabbit
New Features
Bug Fixes