kyvvu-cli 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. kyvvu_cli-1.0.0/LICENSE +190 -0
  2. kyvvu_cli-1.0.0/MANIFEST.in +1 -0
  3. kyvvu_cli-1.0.0/PKG-INFO +50 -0
  4. kyvvu_cli-1.0.0/README.md +24 -0
  5. kyvvu_cli-1.0.0/_build_backend.py +126 -0
  6. kyvvu_cli-1.0.0/kyvvu_cli/__init__.py +4 -0
  7. kyvvu_cli-1.0.0/kyvvu_cli/__main__.py +7 -0
  8. kyvvu_cli-1.0.0/kyvvu_cli/__version__.py +1 -0
  9. kyvvu_cli-1.0.0/kyvvu_cli/_build_info.json +19 -0
  10. kyvvu_cli-1.0.0/kyvvu_cli/agents.py +130 -0
  11. kyvvu_cli-1.0.0/kyvvu_cli/auth.py +314 -0
  12. kyvvu_cli-1.0.0/kyvvu_cli/cli_plugins.py +71 -0
  13. kyvvu_cli-1.0.0/kyvvu_cli/client.py +237 -0
  14. kyvvu_cli-1.0.0/kyvvu_cli/config.py +71 -0
  15. kyvvu_cli-1.0.0/kyvvu_cli/doctor.py +1568 -0
  16. kyvvu_cli-1.0.0/kyvvu_cli/documentation.py +79 -0
  17. kyvvu_cli-1.0.0/kyvvu_cli/init_cmd.py +155 -0
  18. kyvvu_cli-1.0.0/kyvvu_cli/main.py +455 -0
  19. kyvvu_cli-1.0.0/kyvvu_cli/manifests.py +154 -0
  20. kyvvu_cli-1.0.0/kyvvu_cli/policies.py +66 -0
  21. kyvvu_cli-1.0.0/kyvvu_cli/project_environment.py +87 -0
  22. kyvvu_cli-1.0.0/kyvvu_cli/py.typed +0 -0
  23. kyvvu_cli-1.0.0/kyvvu_cli/serve.py +258 -0
  24. kyvvu_cli-1.0.0/kyvvu_cli/supported.py +4 -0
  25. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/AGENTS.md.tmpl +25 -0
  26. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/README.md.tmpl +55 -0
  27. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/agent.py.tmpl +202 -0
  28. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/env.example.tmpl +23 -0
  29. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/gitignore.tmpl +5 -0
  30. kyvvu_cli-1.0.0/kyvvu_cli/templates/default/requirements.txt.tmpl +1 -0
  31. kyvvu_cli-1.0.0/kyvvu_cli/trial_marker.py +222 -0
  32. kyvvu_cli-1.0.0/kyvvu_cli/try_cmd.py +879 -0
  33. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/PKG-INFO +50 -0
  34. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/SOURCES.txt +38 -0
  35. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/dependency_links.txt +1 -0
  36. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/entry_points.txt +2 -0
  37. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/requires.txt +14 -0
  38. kyvvu_cli-1.0.0/kyvvu_cli.egg-info/top_level.txt +2 -0
  39. kyvvu_cli-1.0.0/pyproject.toml +81 -0
  40. kyvvu_cli-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Kyvvu B.V.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1 @@
1
+ include _build_backend.py
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: kyvvu-cli
3
+ Version: 1.0.0
4
+ Summary: Kyvvu command-line tools for policy trials and platform diagnostics
5
+ Author-email: "Kyvvu B.V." <info@kyvvu.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Documentation, https://docs.kyvvu.com/
8
+ Project-URL: Changelog, https://docs.kyvvu.com/reference/changelog
9
+ Project-URL: Issues, https://github.com/Kyvvu/issues/issues
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: kyvvu-engine[serve]<2.0.0,>=1.0.0
14
+ Requires-Dist: kyvvu-baseline<2.0.0,>=1.0.0
15
+ Requires-Dist: kyvvu-templates<2.0.0,>=1.0.0
16
+ Requires-Dist: typer>=0.12
17
+ Requires-Dist: rich>=13
18
+ Requires-Dist: httpx>=0.27
19
+ Requires-Dist: tomli-w>=1.0
20
+ Provides-Extra: claude-code
21
+ Requires-Dist: kyvvu-claude<2.0.0,>=1.0.0; extra == "claude-code"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
24
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # kyvvu-cli
28
+
29
+ The `kyvvu` command-line tool for offline policy trials, diagnostics, local
30
+ policy serving, and platform administration. Install with `uv tool install kyvvu-cli`
31
+ (or `pip install kyvvu-cli`).
32
+
33
+ The command runs without the `kyvvu` Python client. See the
34
+ [CLI documentation](https://docs.kyvvu.com/) for usage.
35
+
36
+ ## CLI plugins
37
+
38
+ An installed distribution can add a `kyvvu <name>` command by declaring an
39
+ entry point in the `kyvvu.cli_plugins` group. The entry point names a Python
40
+ module with a Typer `app`. The module may also expose `status() -> str` for one
41
+ line in `kyvvu integrations` and `doctor() -> kyvvu_cli.doctor.Check` for
42
+ `kyvvu doctor` (including `--json`). Both hooks are optional. For example:
43
+
44
+ ```toml
45
+ [project.entry-points."kyvvu.cli_plugins"]
46
+ myplugin = "my_package.cli"
47
+ ```
48
+
49
+ An import or hook failure prints one warning and leaves other commands and
50
+ diagnostics available.
@@ -0,0 +1,24 @@
1
+ # kyvvu-cli
2
+
3
+ The `kyvvu` command-line tool for offline policy trials, diagnostics, local
4
+ policy serving, and platform administration. Install with `uv tool install kyvvu-cli`
5
+ (or `pip install kyvvu-cli`).
6
+
7
+ The command runs without the `kyvvu` Python client. See the
8
+ [CLI documentation](https://docs.kyvvu.com/) for usage.
9
+
10
+ ## CLI plugins
11
+
12
+ An installed distribution can add a `kyvvu <name>` command by declaring an
13
+ entry point in the `kyvvu.cli_plugins` group. The entry point names a Python
14
+ module with a Typer `app`. The module may also expose `status() -> str` for one
15
+ line in `kyvvu integrations` and `doctor() -> kyvvu_cli.doctor.Check` for
16
+ `kyvvu doctor` (including `--json`). Both hooks are optional. For example:
17
+
18
+ ```toml
19
+ [project.entry-points."kyvvu.cli_plugins"]
20
+ myplugin = "my_package.cli"
21
+ ```
22
+
23
+ An import or hook failure prints one warning and leaves other commands and
24
+ diagnostics available.
@@ -0,0 +1,126 @@
1
+ """Setuptools adapter that preserves source provenance in wheels and sdists.
2
+
3
+ Canonical source; scripts/sync-build-backend.py vendors this file into each
4
+ distribution so source archives build without the monorepo or another package.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import os
11
+ import re
12
+ import shutil
13
+ import subprocess
14
+ import tempfile
15
+ import tomllib
16
+ from pathlib import Path
17
+ from typing import Any
18
+
19
+ PROJECTS = (
20
+ "kyvvu-engine", "kyvvu-baseline", "kyvvu-templates", "kyvvu-sdk", "kyvvu-cli",
21
+ "kyvvu-langchain", "kyvvu-claude", "kyvvu-crewai",
22
+ )
23
+
24
+
25
+ def read_versions(source: Path) -> dict[str, str]:
26
+ versions = {}
27
+ for line in source.read_text().splitlines():
28
+ declaration = line.partition("#")[0].strip()
29
+ if not declaration:
30
+ continue
31
+ match = re.fullmatch(r"([A-Z][A-Z0-9_]*)=(.*)", declaration)
32
+ if not match or match[1] in versions:
33
+ raise ValueError(f"Invalid or duplicate VERSIONS declaration: {declaration}")
34
+ versions[match[1]] = match[2].strip()
35
+ return versions
36
+
37
+
38
+ def checkout_metadata(project: Path) -> dict[str, Any] | None:
39
+ git = shutil.which("git")
40
+ if git is None:
41
+ return None
42
+ try:
43
+ repository = subprocess.check_output( # noqa: S603 - resolved executable; fixed arguments
44
+ [git, "rev-parse", "--show-toplevel"], cwd=project, text=True, stderr=subprocess.DEVNULL,
45
+ ).strip()
46
+ except (OSError, subprocess.CalledProcessError):
47
+ return None
48
+ root = Path(repository)
49
+ if root != project.parent or not (root / "VERSIONS").is_file():
50
+ return None
51
+ tracked = subprocess.run( # noqa: S603 - resolved executable; path follows --
52
+ [git, "ls-files", "--error-unmatch", "--", f"{project.name}/pyproject.toml"],
53
+ cwd=root, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
54
+ )
55
+ if tracked.returncode:
56
+ return None
57
+ commit = subprocess.check_output([git, "rev-parse", "HEAD"], cwd=root, text=True).strip() # noqa: S603
58
+ return {"commit": commit, "versions": read_versions(root / "VERSIONS")}
59
+
60
+
61
+ def validate_metadata(value: Any) -> dict[str, Any]:
62
+ if not isinstance(value, dict) or not isinstance(value.get("commit"), str):
63
+ raise TypeError("Build provenance must name its source commit")
64
+ if not re.fullmatch(r"[0-9a-f]{40}", value["commit"]):
65
+ raise ValueError("Build provenance needs a full 40-character commit SHA")
66
+ versions = value.get("versions")
67
+ if not isinstance(versions, dict) or not {"ENGINE_VERSION", "SDK_VERSION"} <= versions.keys():
68
+ raise ValueError("Build provenance is missing its VERSIONS snapshot")
69
+ if not all(isinstance(key, str) and isinstance(item, str) for key, item in versions.items()):
70
+ raise ValueError("Build provenance versions must be strings")
71
+ return value
72
+
73
+
74
+ def capture_metadata(project: Path) -> Path:
75
+ project = project.resolve()
76
+ config = tomllib.loads((project / "pyproject.toml").read_text())
77
+ module = config["tool"]["setuptools"]["dynamic"]["version"]["attr"].split(".")[0]
78
+ destination = project / module / "_build_info.json"
79
+ metadata = checkout_metadata(project)
80
+ if metadata is None:
81
+ if not destination.is_file():
82
+ raise RuntimeError("Source provenance is unavailable; build from a Git checkout or a prepared sdist")
83
+ metadata = json.loads(destination.read_text())
84
+ payload = json.dumps(validate_metadata(metadata), indent=2, sort_keys=True) + "\n"
85
+ if destination.is_file() and destination.read_text() == payload:
86
+ return destination
87
+ temporary = None
88
+ try:
89
+ with tempfile.NamedTemporaryFile(mode="w", dir=destination.parent, delete=False) as stream:
90
+ temporary = Path(stream.name)
91
+ stream.write(payload)
92
+ temporary.chmod(0o644)
93
+ os.replace(temporary, destination)
94
+ finally:
95
+ if temporary is not None:
96
+ temporary.unlink(missing_ok=True)
97
+ return destination
98
+
99
+
100
+ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
101
+ from setuptools import build_meta
102
+
103
+ capture_metadata(Path(__file__).parent)
104
+ return build_meta.build_wheel(wheel_directory, config_settings, metadata_directory)
105
+
106
+
107
+ def build_sdist(sdist_directory, config_settings=None):
108
+ from setuptools import build_meta
109
+
110
+ capture_metadata(Path(__file__).parent)
111
+ return build_meta.build_sdist(sdist_directory, config_settings)
112
+
113
+
114
+ def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
115
+ from setuptools import build_meta
116
+
117
+ capture_metadata(Path(__file__).parent)
118
+ return build_meta.build_editable(wheel_directory, config_settings, metadata_directory)
119
+
120
+
121
+ def __getattr__(name):
122
+ if name.startswith("__"):
123
+ raise AttributeError(name)
124
+ from setuptools import build_meta
125
+
126
+ return getattr(build_meta, name)
@@ -0,0 +1,4 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Kyvvu B.V.
3
+
4
+ """Kyvvu CLI — command-line interface for the Kyvvu SDK."""
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Kyvvu B.V.
3
+
4
+ """Allow ``python -m kyvvu`` to invoke the CLI."""
5
+ from kyvvu_cli.main import app
6
+
7
+ app()
@@ -0,0 +1 @@
1
+ __version__ = "1.0.0"
@@ -0,0 +1,19 @@
1
+ {
2
+ "commit": "c6dc2dcb8d96d4842ed989267301bfdcb3cfa139",
3
+ "versions": {
4
+ "API_VERSION": "1.0.0",
5
+ "BASELINE_VERSION": "1.0.0",
6
+ "CLAUDE_VERSION": "1.0.0",
7
+ "CLI_VERSION": "1.0.0",
8
+ "CREWAI_VERSION": "1.0.0",
9
+ "ENGINE_VERSION": "1.0.0",
10
+ "LANGCHAIN_VERSION": "1.0.0",
11
+ "MIN_ENGINE_VERSION": "0.13.0",
12
+ "MIN_POLICY_SCHEMA": "1",
13
+ "NEXT_MIN_ENGINE_DATE": "",
14
+ "NEXT_MIN_ENGINE_VERSION": "",
15
+ "SDK_VERSION": "1.0.0",
16
+ "TEMPLATES_VERSION": "1.0.0",
17
+ "WEB_VERSION": "1.0.0"
18
+ }
19
+ }
@@ -0,0 +1,130 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Kyvvu B.V.
3
+
4
+ """Agent inspection command: list-agents, and agent key -> id resolution."""
5
+ from __future__ import annotations
6
+
7
+ import re
8
+ from typing import Any, Optional
9
+
10
+ import typer
11
+ from rich.console import Console
12
+ from rich.table import Table
13
+
14
+ from kyvvu_cli.client import api_get, require_cli_pat
15
+ from kyvvu_cli.config import get_api_url
16
+
17
+ console = Console()
18
+
19
+ # The platform's agent ids: ``agent_`` plus hex (``agents/service.py``).
20
+ _AGENT_ID_RE = re.compile(r"agent_[0-9a-f]+")
21
+
22
+
23
+ def _fetch_agents(
24
+ api_key: str,
25
+ api_url: str,
26
+ *,
27
+ environment: Optional[str] = None,
28
+ include_inactive: bool = False,
29
+ ) -> list[Any]:
30
+ """Return the workspace's agents from ``GET /api/v1/agents``.
31
+
32
+ The platform filters out deactivated agents unless ``include_inactive=true``
33
+ is sent, so the filtering is the server's, not ours (#807).
34
+ """
35
+ params: dict[str, str] = {"limit": "1000"}
36
+ if environment:
37
+ params["environment"] = environment
38
+ if include_inactive:
39
+ params["include_inactive"] = "true"
40
+ agents = api_get("/api/v1/agents", params=params, api_key=api_key, api_url=api_url)
41
+ if isinstance(agents, dict) and "items" in agents:
42
+ agents = agents["items"]
43
+ if not isinstance(agents, list):
44
+ agents = [agents] if agents else []
45
+ return agents
46
+
47
+
48
+ def resolve_agent_id(value: str, *, api_key: str, api_url: str) -> str:
49
+ """Return the platform ``agent_id`` for *value*, an agent id or an agent key.
50
+
51
+ ``--agent-id`` used to take only the platform-assigned ``agent_...`` id,
52
+ and a key was answered with ``404 Agent not found`` (#795). A value shaped
53
+ like an id is passed through untouched; anything else is looked up among
54
+ the workspace's active agents by ``agent_key``, in the one list call
55
+ ``list-agents`` makes.
56
+
57
+ Args:
58
+ value: What the user passed to ``--agent-id``.
59
+ api_key: The CLI PAT.
60
+ api_url: The platform URL.
61
+
62
+ Returns:
63
+ The agent's ``agent_id``.
64
+
65
+ Raises:
66
+ typer.Exit: With status 1 when no agent, or more than one, has that key.
67
+ """
68
+ if _AGENT_ID_RE.fullmatch(value):
69
+ return value
70
+ matches = [
71
+ a for a in _fetch_agents(api_key, api_url)
72
+ if a.get("agent_key") == value
73
+ ]
74
+ ids = [str(a.get("agent_id", a.get("id", ""))) for a in matches]
75
+ if len(ids) == 1:
76
+ return ids[0]
77
+ if not ids:
78
+ typer.echo(
79
+ f"No active agent with id or key '{value}' in this workspace. "
80
+ "Run `kyvvu list-agents` to see them.",
81
+ err=True,
82
+ )
83
+ else:
84
+ typer.echo(
85
+ f"More than one agent has the key '{value}' ({', '.join(ids)}). "
86
+ "Pass the agent id instead.",
87
+ err=True,
88
+ )
89
+ raise typer.Exit(1)
90
+
91
+
92
+ def list_agents(
93
+ environment: Optional[str] = None,
94
+ include_inactive: bool = False,
95
+ ) -> None:
96
+ """List registered agents.
97
+
98
+ Args:
99
+ environment: Only agents in this environment.
100
+ include_inactive: Also list deactivated agents. Sent to the platform
101
+ as ``include_inactive=true``; it never returns them otherwise.
102
+ """
103
+ api_key = require_cli_pat()
104
+ api_url = get_api_url()
105
+
106
+ agents = _fetch_agents(
107
+ api_key, api_url, environment=environment, include_inactive=include_inactive
108
+ )
109
+
110
+ if not agents:
111
+ typer.echo("No agents found.")
112
+ return
113
+
114
+ table = Table(show_header=True, header_style="bold")
115
+ table.add_column("AGENT_KEY")
116
+ table.add_column("AGENT_ID")
117
+ table.add_column("NAME")
118
+ table.add_column("ENVIRONMENT")
119
+ table.add_column("ACTIVE")
120
+
121
+ for a in agents:
122
+ table.add_row(
123
+ a.get("agent_key", ""),
124
+ a.get("agent_id", a.get("id", "")),
125
+ a.get("name", ""),
126
+ a.get("environment", ""),
127
+ "\u2713" if a.get("active", True) else "\u2717",
128
+ )
129
+
130
+ console.print(table)