Skip to content

refactor: share the vera command skeleton in vera_cli/config.py - #258

Merged
luca-belli merged 2 commits into
mainfrom
refactor/cli-shared-command
Oct 13, 2026
Merged

luca-belli merged 2 commits into
mainfrom
refactor/cli-shared-command

Conversation

@luca-belli

Copy link
Copy Markdown
Collaborator

Summary

The five command modules repeated the same run, resolve_configs, common flags and pass-through _run_config. Following the #255 review discussion, this moves the shared parts into vera_cli/config.py. No behavior change.

Stacked on the pipeline-pooling PR, because both change vera_cli/pipeline.py.

  • New shared helpers in vera_cli/config.py:
    • run_command: resolve, --print, --debug, echo, execute; handles sync and async _execute
    • resolve_with: config-or-flags dispatch plus invalid <label> config wrapping
    • add_common_flags: --config, -d/--debug, --print, optional --sample/--into, and the handler, in one fixed order
    • config_section, string_list
  • Per command: each run/resolve_configs is now one call; the wrappers stay because tests and pipeline use them.
  • Removed:
    • the four pass-through _run_configs (RunConfig is built inline)
    • pipeline._render (render_invocation now accepts anything with to_dict())
    • judge._string_list (now config.string_list, which config_paths also uses)
  • Kept per command: config sections, DEFAULTS, _from_cli/_from_config, _execute, run-defining flags. Also kept: the type checks in _from_config that guard path helpers before the dataclass exists, since removing them would change error messages.
  • Docs: vera_cli/README.md ("Adding a command"), module docstrings, CHANGELOG. Also fixes a stale code comment pointing at the deleted TODO file.
  • 8 files, +420 / −554.

Not addressed here: pipeline still calls other commands' private resolvers. That's recorded in the roadmap Backlog.

Test plan

  • --help for all 5 commands is byte-identical to before
  • --print output (4 commands) and 7 error-path messages are byte-identical to before
  • uv run pytest -m "not live" (1215 passed), with no test changes
  • ruff check, ruff format --check, pyright generate score utils vera_cli vera.py

🤖 Generated with Claude Code

@luca-belli
luca-belli added this pull request to stack #259 October 13, 2026 17:36
Comment thread vera_cli/config.py


def render_invocation(run_config: RunConfig, *, command: str) -> str:
class _Renderable(Protocol):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

what is this? what's the purpose? why there is no docstring

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's a typing-only description of "anything with a to_dict()" (a Protocol). It exists so render_invocation, and run_command's --print path, accept both a RunConfig (generate, judge, score, pool) and a pipeline's PipelineRun. Those two share no base class, but both serialize to the config dict --print emits. Before this PR, pipeline carried its own copy of render_invocation (_render) for that reason. You're right that it needed a docstring; added in 145ac85.

Comment thread vera_cli/config.py Outdated
# (fields, defaults, the domain call, run-defining flags) live in the command
# modules; the identical parts live here.

Run = TypeVar("Run")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

what is this supposed to wrap? every run command?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't wrap anything. It's a type variable meaning "one resolved run, as this command's resolve_configs returns it": RunConfig for generate, judge, score and pool, PipelineRun for pipeline. Using a type variable instead of a fixed type lets the type checker confirm that what resolve returns is what execute, echo and debug_of receive, for whichever command calls run_command. In 145ac85 I renamed it ResolvedRun, added a comment saying this, and bounded it to _Renderable, which also removed one type: ignore.

@luca-belli
luca-belli marked this pull request as ready for review October 13, 2026 17:58
@luca-belli
luca-belli force-pushed the refactor/cli-shared-command branch from 145ac85 to b52c0ba Compare October 13, 2026 20:10
@jgieringer
jgieringer requested a balanced review from Copilot October 13, 2026 21:13

Copilot AI 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.

🟢 Approval recommended

The refactor preserves existing command semantics while consistently removing duplicated implementation.

0 open findings

What changed in this PR

Centralizes the shared CLI command lifecycle in vera_cli/config.py without changing behavior.

Changes:

  • Adds shared execution, resolution, flag-registration, and config helpers.
  • Updates all five command modules to use the shared skeleton.
  • Documents the refactor and removes redundant private helpers.
File Description
vera_cli/​config.py Adds shared command helpers.
vera_cli/​generate.py Adopts shared command handling.
vera_cli/​judge.py Adopts helpers and shared list validation.
vera_cli/​pipeline.py Adopts shared handling and rendering.
vera_cli/​pool.py Adopts shared command handling.
vera_cli/​score.py Adopts shared command handling.
vera_cli/​README.md Documents the command skeleton.
CHANGELOG.md Records the refactor.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jgieringer jgieringer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

configs: simplified.

@luca-belli
luca-belli force-pushed the refactor/cli-shared-command branch from b52c0ba to b36658e Compare October 13, 2026 21:56
@luca-belli
luca-belli requested a review from a team as a code owner October 13, 2026 21:56
Base automatically changed from feat/pipeline-pools to main October 13, 2026 21:57
luca-belli and others added 2 commits October 13, 2026 14:57
run_command, resolve_with, add_common_flags, config_section and
string_list replace code each command repeated; the pass-through
_run_config helpers and pipeline's render_invocation copy are gone.
Help text, --print output and error messages are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@luca-belli
luca-belli force-pushed the refactor/cli-shared-command branch from b36658e to fc80328 Compare October 13, 2026 21:57
@luca-belli
luca-belli merged commit c736ee1 into main Oct 13, 2026
3 checks passed
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.

3 participants