judgevet.adapters.inbound.cli_composition

Status: draft.

judgevet.adapters.inbound.cli_composition

Compose CLI calls with explicitly selected application providers.

Input parsing precedes provider acquisition. The application owns configuration, state transformations, audit and spend accounting through its selected provider. Image manifests are bounded and validated before entering the same resource scope.

Examples:

from judgevet.adapters.inbound.cli_composition import ProviderSelection
from judgevet.testing import FakeSystemOnePort

provider = FakeSystemOnePort()
selection = ProviderSelection(provider, None)
assert selection.port is provider
See Also

CliCommand dataclass

Bind the shared command grammar to one application's dispatch.

Attributes:

Name Type Description
dispatch CommandDispatch

Selected composition root.

inputs CommandInputs

Existing explicit input validation.

Examples:

from judgevet.adapters.inbound.cli_composition import CliCommand

command = CliCommand(
    lambda state, questions, model, key, output, policies: 0,
    lambda state, questions, states, queries, policies, output: ("s", "{}"),
)
assert callable(command.run)

run(ctx, arguments=None, model=typer.Option('jev-latest', help='Model to use'), api_key=typer.Option(None, help='TypeSafe API key'), json_output=typer.Option(False, '--json', help='Output as JSON'))

Validate command inputs and dispatch to the selected composition root.

Parameters:

Name Type Description Default
ctx Context

Invocation metadata and application provider selection.

required
arguments Annotated[list[str] | None, Argument(help='state: State to evaluate. questions: Questions as JSON string.', metavar=[STATE][QUESTIONS])]

Optional positional state followed by questions JSON.

None
model str

Model to use.

Option('jev-latest', help='Model to use')
api_key str | None

TypeSafe API key.

Option(None, help='TypeSafe API key')
json_output bool

Output as JSON.

Option(False, '--json', help='Output as JSON')

Returns:

Type Description
int

0 on success. Failures raise typer.Exit.

Raises:

Type Description
Exit

If input validation or the judgment fails.

BadParameter

If required legacy positional arguments are absent.

ProviderSelection dataclass

Retain one application's provider selection without acquiring it.

Attributes:

Name Type Description
port SystemOnePort | None

Borrowed provider, if supplied.

factory ProviderFactory | None

Owning context factory, if supplied.

Examples:

from judgevet.adapters.inbound.cli_composition import ProviderSelection
from judgevet.testing import FakeSystemOnePort

selection = ProviderSelection(FakeSystemOnePort(), None)
assert selection.factory is None

run_selected(selection, state, questions, model, as_json, files, callbacks)

Validate input, call the selected provider and render its typed response.

Parameters:

Name Type Description Default
selection ProviderSelection

Explicit borrowed port or owning factory.

required
state str

Existing state string interpretation.

required
questions str

Existing question JSON.

required
model str

Requested model identifier.

required
as_json bool

Select machine output.

required
files FileInputs

Optional explicit policy and evidence paths.

required
callbacks CliCallbacks

Existing parsing and rendering boundaries.

required

Returns:

Type Description
int

Zero for success, three for unmet policy, or one for handled failure.