Skip to content

Agent CLI parsing#543

Open
M-R-Schaefer wants to merge 4 commits intomainfrom
agent-parsing
Open

Agent CLI parsing#543
M-R-Schaefer wants to merge 4 commits intomainfrom
agent-parsing

Conversation

@M-R-Schaefer
Copy link
Copy Markdown
Contributor

@M-R-Schaefer M-R-Schaefer commented Mar 12, 2026

Adds some subcommands to apax schema that allow navigating the individual sections of the apax config files. Convenient for agents to understand the nested parameters in the trianing and MD configs.

Summary by CodeRabbit

  • New Features

    • Added schema subcommands to inspect train and md configuration parameters
    • Introduced VSCode JSON schema file generation for configuration files
    • Added template generation utilities for creating config files with pre-filled default values
    • Improved configuration validation with unified error handling and clearer error messages
  • Configuration Changes

    • Adjusted default loss weights in training templates (forces and energy reduced from 4.0 to 1.0)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

This change refactors the CLI infrastructure to centralize Typer configuration, introduces new schema navigation and validation modules, and adds JSON schema generation capabilities alongside improved config validation with template support and VSCode integration.

Changes

Cohort / File(s) Summary
CLI Refactoring
apax/cli/apax_app.py
Introduces centralized Typer options bundle (_TYPER_OPTS), new schema_app with train/md/vscode subcommands, refactored validation workflow with _validate_config and _format_errors helpers, template writing utilities (_write_template), and enhanced template support with _TEMPLATE_DATA_DEFAULTS constants.
Schema Navigation & Introspection
apax/config/flat_schema.py, apax/config/schema_navigation.py
New modules providing JSON schema introspection: flat_schema.py flattens Pydantic models into human-readable parameter tables; schema_navigation.py implements schema traversal DSL with support for references, variants (oneOf/anyOf), and hierarchical path filtering.
Template Configuration
apax/cli/templates/train_config_full.yaml, apax/cli/templates/train_config_minimal.yaml
Minor weight adjustments: reduced "forces" loss weight from 4.0 to 1.0 in full template and reduced "energy" loss weight from 4.0 to 1.0 in minimal template.

Sequence Diagrams

sequenceDiagram
    participant User
    participant CLI as schema command
    participant Navigator as schema_navigation
    participant Output

    User->>CLI: schema train [section] [--keywords] [--flat]
    CLI->>Navigator: filter_schema(schema, section)
    Navigator->>Navigator: resolve $refs and variants
    Navigator-->>CLI: (node, error?)
    
    alt Section found
        CLI->>Navigator: print_keywords(schema, section)
        Navigator->>Navigator: aggregate properties & variants
        Navigator-->>CLI: keyword list
        CLI->>Output: print formatted keywords
    else Section not found
        CLI->>Output: print error message
    end
    
    User->>CLI: schema md --keywords
    Note over CLI,Output: Similar flow for md configuration
Loading
sequenceDiagram
    participant User
    participant CLI as validate command
    participant Validator as validation logic
    participant Template as template handling
    participant Output

    User->>CLI: validate train-config config.yaml [--template]
    CLI->>Validator: _validate_config(TrainConfig, path, config, label)
    Validator->>Validator: load and parse config YAML
    
    alt Template requested
        Validator->>Template: apply _TEMPLATE_DATA_DEFAULTS
        Template-->>Validator: config with defaults
    end
    
    Validator->>Validator: pydantic validation
    
    alt Validation succeeds
        Validator->>Output: print success
    else Validation fails
        Validator->>Validator: _format_errors(ValidationError)
        Validator->>Output: print formatted errors
        Validator->>CLI: exit(1)
    end
Loading
sequenceDiagram
    participant User
    participant CLI as schema vscode
    participant Generator as schema handler
    participant FileIO as file system

    User->>CLI: schema vscode
    CLI->>Generator: _handle_schema(TrainConfig, "train", ...)
    Generator->>Generator: generate JSON schema for config
    Generator->>FileIO: write to .vscode/settings.json
    FileIO-->>Generator: file written
    
    CLI->>Generator: _handle_schema(MDConfig, "md", ...)
    Generator->>Generator: generate JSON schema for config
    Generator->>FileIO: append/update .vscode/settings.json
    FileIO-->>Generator: file written
    
    CLI->>Output: print success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hoppy schemas now align,
Validation rules combine with mine,
Flat tables leap and templates sing,
VSCode knows each nested thing,
A CLI garden, fresh and bright,
Where configs bloom in structured light! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Agent CLI parsing' is vague and generic, failing to clearly convey the main changes which involve adding schema navigation subcommands and configuration validation features. Consider a more specific title such as 'Add schema navigation subcommands for configuration inspection' or 'Implement schema CLI subcommands for agent-friendly config access' to better reflect the primary changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch agent-parsing

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 and usage tips.

@M-R-Schaefer M-R-Schaefer marked this pull request as ready for review March 12, 2026 11:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apax/cli/apax_app.py (2)

219-223: Placeholder paths use /tmp which triggers security lint warnings.

These paths are validation placeholders and never used for actual file operations, so the security risk is minimal. However, using clearly fictional paths would silence the linter and make intent clearer.

♻️ Alternative placeholder paths
 _TEMPLATE_DATA_DEFAULTS = {
-    "directory": "/tmp/apax_validate",
-    "experiment": "placeholder",
-    "data_path": "/tmp/apax_validate/placeholder.extxyz",
+    "directory": "PLACEHOLDER_DIRECTORY",
+    "experiment": "PLACEHOLDER_EXPERIMENT",
+    "data_path": "PLACEHOLDER_DATA_PATH",
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apax/cli/apax_app.py` around lines 219 - 223, The placeholder defaults in
_TEMPLATE_DATA_DEFAULTS use /tmp which triggers security linters; update the
dict (symbol: _TEMPLATE_DATA_DEFAULTS in apax_app.py) to use clearly
fictional/nonexistent paths (e.g. "/nonexistent/apax_validate" or
"/placeholder/path/apax_validate") for "directory" and "data_path" while keeping
"experiment": "placeholder" unchanged so the values remain clearly fake and
never used for real file operations.

206-216: Consider suppressing implicit exception chaining.

When raising typer.Exit inside an except block, Python implicitly chains the exceptions. Since the validation error is already formatted and printed, adding from None would produce cleaner output without the "During handling of the above exception" message.

♻️ Suggested improvement
     except ValidationError as e:
         print(f"{e.error_count()} validation errors for config")
         print(_format_errors(e))
         console.print("Configuration Invalid!", style="red3")
-        raise typer.Exit(code=1)
+        raise typer.Exit(code=1) from None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apax/cli/apax_app.py` around lines 206 - 216, The except block in
_validate_config currently raises typer.Exit while handling a ValidationError,
which causes implicit exception chaining and extra traceback text; modify the
raise to suppress chaining by re-raising typer.Exit from None (i.e., use "raise
typer.Exit(code=1) from None") so the printed/ formatted ValidationError remains
the only error output and no "During handling of the above exception" appears;
update the raise in the except block that catches ValidationError in
_validate_config accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apax/cli/apax_app.py`:
- Around line 219-223: The placeholder defaults in _TEMPLATE_DATA_DEFAULTS use
/tmp which triggers security linters; update the dict (symbol:
_TEMPLATE_DATA_DEFAULTS in apax_app.py) to use clearly fictional/nonexistent
paths (e.g. "/nonexistent/apax_validate" or "/placeholder/path/apax_validate")
for "directory" and "data_path" while keeping "experiment": "placeholder"
unchanged so the values remain clearly fake and never used for real file
operations.
- Around line 206-216: The except block in _validate_config currently raises
typer.Exit while handling a ValidationError, which causes implicit exception
chaining and extra traceback text; modify the raise to suppress chaining by
re-raising typer.Exit from None (i.e., use "raise typer.Exit(code=1) from None")
so the printed/ formatted ValidationError remains the only error output and no
"During handling of the above exception" appears; update the raise in the except
block that catches ValidationError in _validate_config accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 41b99637-97eb-457b-baa1-880e3904937b

📥 Commits

Reviewing files that changed from the base of the PR and between be8c87c and c94d8a6.

📒 Files selected for processing (5)
  • apax/cli/apax_app.py
  • apax/cli/templates/train_config_full.yaml
  • apax/cli/templates/train_config_minimal.yaml
  • apax/config/flat_schema.py
  • apax/config/schema_navigation.py

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