Skip to content

Commit cd13097

Browse files
committed
feat(oar): report installed version
1 parent 9d041c3 commit cd13097

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎projects/openshell-agent-runner/docs/reference.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ agent_markdown: true
1010

1111
| Command | Purpose |
1212
| --- | --- |
13+
| `oar --version` | Display the installed OAR version. |
1314
| `oar init PROFILE_ROOT --model MODEL_ID` | Create editable copies of the packaged profiles. |
1415
| `oar validate PROFILE_DIRECTORY` | Check the profile and its local resources. |
1516
| `oar doctor` | Display the OpenShell version, gateway status, and inference configuration. |

‎projects/openshell-agent-runner/src/openshell_agent_runner/cli.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from __future__ import annotations
77

88
import shlex
9+
from importlib.metadata import PackageNotFoundError
10+
from importlib.metadata import version as distribution_version
911
from pathlib import Path
1012
from typing import Annotated, NoReturn
1113

@@ -20,6 +22,14 @@
2022
from openshell_agent_runner.profile_init import ThinkingLevel, initialize_profiles
2123
from openshell_agent_runner.runner import RunRequest, render_dry_run, run_agent
2224

25+
26+
def version_callback(value: bool) -> None:
27+
"""Print the installed OAR version when requested."""
28+
if value:
29+
typer.echo(f"oar {_installed_version()}")
30+
raise typer.Exit()
31+
32+
2333
app = typer.Typer(
2434
help="Launch ephemeral agents for single tasks in OpenShell sandboxes.",
2535
no_args_is_help=True,
@@ -28,6 +38,21 @@
2838
)
2939

3040

41+
@app.callback()
42+
def main(
43+
version: Annotated[
44+
bool | None,
45+
typer.Option(
46+
"--version",
47+
callback=version_callback,
48+
is_eager=True,
49+
help="Show the installed OAR version and exit.",
50+
),
51+
] = None,
52+
) -> None:
53+
"""Launch ephemeral agents for single tasks in OpenShell sandboxes."""
54+
55+
3156
class ProfileTaskHelpCommand(TyperCommand):
3257
"""Show focused help when a profile task is selected."""
3358

@@ -215,6 +240,13 @@ def _fail(error: OarError) -> NoReturn:
215240
raise typer.Exit(1)
216241

217242

243+
def _installed_version() -> str:
244+
try:
245+
return distribution_version("openshell-agent-runner")
246+
except PackageNotFoundError:
247+
return "unknown"
248+
249+
218250
def _profile_task_selection(args: list[str]) -> tuple[Path, str] | None:
219251
if not args or args[0].startswith("-"):
220252
return None

‎projects/openshell-agent-runner/tests/test_cli.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import shutil
5+
from importlib.metadata import PackageNotFoundError
6+
from importlib.metadata import version as distribution_version
57
from pathlib import Path
68

79
import pytest
@@ -28,6 +30,30 @@ def test_root_help_lists_commands() -> None:
2830
assert result.exit_code == 0
2931
for command in ("init", "validate", "run", "doctor"):
3032
assert command in result.stdout
33+
assert "--version" in result.stdout
34+
35+
36+
def test_version_reports_installed_distribution_version() -> None:
37+
result = CliRunner().invoke(app, ["--version"])
38+
39+
assert result.exit_code == 0
40+
assert result.stdout == f"oar {distribution_version('openshell-agent-runner')}\n"
41+
42+
43+
def test_version_handles_unavailable_distribution_metadata(
44+
monkeypatch: pytest.MonkeyPatch,
45+
) -> None:
46+
def missing_distribution(_distribution_name: str) -> str:
47+
raise PackageNotFoundError
48+
49+
monkeypatch.setattr(
50+
"openshell_agent_runner.cli.distribution_version", missing_distribution
51+
)
52+
53+
result = CliRunner().invoke(app, ["--version"])
54+
55+
assert result.exit_code == 0
56+
assert result.stdout == "oar unknown\n"
3157

3258

3359
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)