qbraid-cli 0.17.0__tar.gz → 0.17.2__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.
- {qbraid_cli-0.17.0/qbraid_cli.egg-info → qbraid_cli-0.17.2}/PKG-INFO +4 -4
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/pyproject.toml +4 -4
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/app.py +515 -9
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/ai/token.py +24 -3
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/registry.py +28 -14
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2/qbraid_cli.egg-info}/PKG-INFO +4 -4
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli.egg-info/requires.txt +3 -3
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/LICENSE +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/README.md +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/_build_info.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/_version.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/account/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/account/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/admin/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/admin/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/admin/headers.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/admin/validation.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/keep_alive.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/permission_response.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/provider_children.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/queue.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/agents/work.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/ai/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/ai/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/artifacts/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/artifacts/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/comms/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/comms/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/instances.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/profiles.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/server.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/compute/ssh.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/configure/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/configure/actions.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/configure/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/devices/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/devices/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/devices/validation.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/activate.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/create.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/data_handling.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/groups.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/publish.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/envs/share.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/exceptions.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/handlers.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/jobs/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/jobs/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/jobs/groups.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/kernels/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/kernels/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/lab/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/lab/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/main.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/pip/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/pip/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/pip/hooks.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/projects/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/projects/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/py.typed +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/skills/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/skills/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/troubleshoot/__init__.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli/troubleshoot/app.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli.egg-info/SOURCES.txt +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli.egg-info/dependency_links.txt +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli.egg-info/entry_points.txt +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/qbraid_cli.egg-info/top_level.txt +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/setup.cfg +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/tests/test_cli_e2e.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/tests/test_register_client.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/tests/test_status_colors.py +0 -0
- {qbraid_cli-0.17.0 → qbraid_cli-0.17.2}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qbraid-cli
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.2
|
|
4
4
|
Summary: Command Line Interface for interacting with all parts of the qBraid platform.
|
|
5
5
|
Author-email: qBraid Development Team <contact@qbraid.com>
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -30,11 +30,11 @@ Requires-Dist: typer>=0.12.1
|
|
|
30
30
|
Requires-Dist: rich>=10.11.0
|
|
31
31
|
Requires-Dist: click<=8.5.1
|
|
32
32
|
Requires-Dist: questionary>=2.0.0
|
|
33
|
-
Requires-Dist: qbraid-core>=0.6.
|
|
33
|
+
Requires-Dist: qbraid-core>=0.6.56
|
|
34
34
|
Provides-Extra: compute
|
|
35
|
-
Requires-Dist: qbraid-core[compute]>=0.6.
|
|
35
|
+
Requires-Dist: qbraid-core[compute]>=0.6.56; extra == "compute"
|
|
36
36
|
Provides-Extra: envs
|
|
37
|
-
Requires-Dist: qbraid-core[environments]>=0.6.
|
|
37
|
+
Requires-Dist: qbraid-core[environments]>=0.6.56; extra == "envs"
|
|
38
38
|
Provides-Extra: dev
|
|
39
39
|
Requires-Dist: isort; extra == "dev"
|
|
40
40
|
Requires-Dist: black; extra == "dev"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "qbraid-cli"
|
|
7
|
-
version = "0.17.
|
|
7
|
+
version = "0.17.2"
|
|
8
8
|
description = "Command Line Interface for interacting with all parts of the qBraid platform."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "qBraid Development Team", email = "contact@qbraid.com" }]
|
|
@@ -32,7 +32,7 @@ dependencies = [
|
|
|
32
32
|
"rich>=10.11.0",
|
|
33
33
|
"click<=8.5.1",
|
|
34
34
|
"questionary>=2.0.0",
|
|
35
|
-
"qbraid-core>=0.6.
|
|
35
|
+
"qbraid-core>=0.6.56",
|
|
36
36
|
]
|
|
37
37
|
requires-python = ">= 3.10"
|
|
38
38
|
|
|
@@ -43,8 +43,8 @@ Documentation = "https://docs.qbraid.com/v2/cli/api-reference/qbraid"
|
|
|
43
43
|
Discord = "https://discord.gg/KugF6Cnncm"
|
|
44
44
|
|
|
45
45
|
[project.optional-dependencies]
|
|
46
|
-
compute = ["qbraid-core[compute]>=0.6.
|
|
47
|
-
envs = ["qbraid-core[environments]>=0.6.
|
|
46
|
+
compute = ["qbraid-core[compute]>=0.6.56"]
|
|
47
|
+
envs = ["qbraid-core[environments]>=0.6.56"]
|
|
48
48
|
dev = ["isort", "black", "pytest", "pytest-cov", "pytest-asyncio"]
|
|
49
49
|
|
|
50
50
|
[project.scripts]
|
|
@@ -1884,6 +1884,19 @@ def _backend_launcher(backend):
|
|
|
1884
1884
|
return AgentLauncher(backend=backend.value)
|
|
1885
1885
|
|
|
1886
1886
|
|
|
1887
|
+
class MessagingMode(str, Enum):
|
|
1888
|
+
"""An agent's messaging: open, or restricted to the role rules."""
|
|
1889
|
+
|
|
1890
|
+
OPEN = "open"
|
|
1891
|
+
RESTRICTED = "restricted"
|
|
1892
|
+
|
|
1893
|
+
|
|
1894
|
+
def _is_messaging_mode_error(error: BaseException) -> bool:
|
|
1895
|
+
"""Core's ``MessagingModeError`` (not an ``AgentLauncherError``), by name, so
|
|
1896
|
+
an older qbraid-core without the class still imports."""
|
|
1897
|
+
return any(cls.__name__ == "MessagingModeError" for cls in type(error).__mro__)
|
|
1898
|
+
|
|
1899
|
+
|
|
1887
1900
|
class ExecutionMode(str, Enum):
|
|
1888
1901
|
"""Codex command isolation, independent of approval prompts."""
|
|
1889
1902
|
|
|
@@ -2036,6 +2049,107 @@ def agents_readiness(
|
|
|
2036
2049
|
raise typer.Exit(1)
|
|
2037
2050
|
|
|
2038
2051
|
|
|
2052
|
+
class TrustTool(str, Enum):
|
|
2053
|
+
"""Agents with a folder-trust prompt."""
|
|
2054
|
+
|
|
2055
|
+
CLAUDE = "claude"
|
|
2056
|
+
CODEX = "codex"
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
@agents_app.command("trust-folder")
|
|
2060
|
+
def agents_trust_folder(
|
|
2061
|
+
folder: Optional[str] = typer.Argument(None, help="Folder to decide about (default: here)."),
|
|
2062
|
+
tool_choice: TrustTool = typer.Option(TrustTool.CLAUDE, "--tool", help="Agent whose trust to set."),
|
|
2063
|
+
no: bool = typer.Option(False, "--no", help="Undo: stop trusting your home folder."),
|
|
2064
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip the confirmation question."),
|
|
2065
|
+
json_output: bool = typer.Option(False, "--json", help="Print the recorded decision."),
|
|
2066
|
+
):
|
|
2067
|
+
"""Decide whether an agent trusts a folder.
|
|
2068
|
+
|
|
2069
|
+
A trusted folder is not asked about when an agent starts there, and its
|
|
2070
|
+
own settings, hooks and MCP servers run. For
|
|
2071
|
+
your home folder the decision is standing (it covers every launch there,
|
|
2072
|
+
including unattended ones) and is recorded with when and how; undo it with
|
|
2073
|
+
--no. Only you can decide: an agent calling this is refused.
|
|
2074
|
+
"""
|
|
2075
|
+
try:
|
|
2076
|
+
from qbraid_core.services.agents.trust import ( # type: ignore[attr-defined]
|
|
2077
|
+
HOME_TRUST_WARNING,
|
|
2078
|
+
FolderTrustDecisionError,
|
|
2079
|
+
decide_folder_trust,
|
|
2080
|
+
folder_trust_target,
|
|
2081
|
+
)
|
|
2082
|
+
except ImportError:
|
|
2083
|
+
typer.echo("Folder-trust decisions require a newer qbraid-core.", err=True)
|
|
2084
|
+
raise typer.Exit(2) from None
|
|
2085
|
+
import importlib
|
|
2086
|
+
|
|
2087
|
+
trust_module = importlib.import_module("qbraid_core.services.agents.trust")
|
|
2088
|
+
caller_is_agent = getattr(trust_module, "_caller_is_agent", None)
|
|
2089
|
+
if callable(caller_is_agent) and caller_is_agent():
|
|
2090
|
+
# Refused before any warning or question: the decision is the person's.
|
|
2091
|
+
typer.echo("Only the person decides whether to trust a folder; an agent cannot.", err=True)
|
|
2092
|
+
raise typer.Exit(1)
|
|
2093
|
+
tool = tool_choice.value
|
|
2094
|
+
target = os.path.abspath(os.path.expanduser(folder or os.getcwd()))
|
|
2095
|
+
trusted = not no
|
|
2096
|
+
if trusted:
|
|
2097
|
+
# Everything that would refuse is checked before the person is asked.
|
|
2098
|
+
try:
|
|
2099
|
+
plan = folder_trust_target(tool, target)
|
|
2100
|
+
except FolderTrustDecisionError as exc:
|
|
2101
|
+
typer.echo(str(exc), err=True)
|
|
2102
|
+
raise typer.Exit(1) from None
|
|
2103
|
+
# The question and the warning go to stderr: stdout stays the answer
|
|
2104
|
+
# (pure JSON with --json), and the warning is never piped away.
|
|
2105
|
+
if plan["home"]:
|
|
2106
|
+
typer.echo(HOME_TRUST_WARNING, err=True)
|
|
2107
|
+
question = f"Trust your home folder {plan['folder']}?"
|
|
2108
|
+
else:
|
|
2109
|
+
question = (
|
|
2110
|
+
f"Trust {plan['trustedAs']} for {tool}? Its own settings, hooks and MCP servers, "
|
|
2111
|
+
"and those of folders below it that are not git repositories, will run without asking."
|
|
2112
|
+
)
|
|
2113
|
+
if not yes:
|
|
2114
|
+
if not _can_ask():
|
|
2115
|
+
typer.echo(
|
|
2116
|
+
"Refusing to decide without a terminal to ask you; pass --yes if you mean it.",
|
|
2117
|
+
err=True,
|
|
2118
|
+
)
|
|
2119
|
+
raise typer.Exit(1)
|
|
2120
|
+
if not typer.confirm(question, default=False, err=True):
|
|
2121
|
+
typer.echo("Nothing changed.", err=True)
|
|
2122
|
+
raise typer.Exit(1)
|
|
2123
|
+
try:
|
|
2124
|
+
result = decide_folder_trust(tool, target, trusted, via="cli")
|
|
2125
|
+
except FolderTrustDecisionError as exc:
|
|
2126
|
+
typer.echo(str(exc), err=True)
|
|
2127
|
+
raise typer.Exit(1) from None
|
|
2128
|
+
if result.get("appliedNow") is False:
|
|
2129
|
+
# Recorded, but Claude's config still says the opposite: exit 3, like a
|
|
2130
|
+
# partial delivery, so a script does not take it as done.
|
|
2131
|
+
state = "trusted" if not result["trusted"] else "not trusted"
|
|
2132
|
+
if json_output:
|
|
2133
|
+
print(json.dumps(result))
|
|
2134
|
+
else:
|
|
2135
|
+
typer.echo(
|
|
2136
|
+
f"Recorded, but not applied yet: your home folder stays {state} until the next "
|
|
2137
|
+
"Claude launch through qBraid (Claude's config was busy). A plain `claude` started "
|
|
2138
|
+
"before then still sees the old setting."
|
|
2139
|
+
)
|
|
2140
|
+
raise typer.Exit(3)
|
|
2141
|
+
if json_output:
|
|
2142
|
+
print(json.dumps(result))
|
|
2143
|
+
return
|
|
2144
|
+
shown = result.get("trustedAs") or result["folder"]
|
|
2145
|
+
if not result["trusted"]:
|
|
2146
|
+
typer.echo(f"{result['folder']} is no longer trusted by your choice.")
|
|
2147
|
+
elif result["standing"]:
|
|
2148
|
+
typer.echo(f"{shown} is trusted by your choice. Undo: qbraid agents trust-folder ~ --no")
|
|
2149
|
+
else:
|
|
2150
|
+
typer.echo(f"{shown} is trusted for {tool}.")
|
|
2151
|
+
|
|
2152
|
+
|
|
2039
2153
|
@agents_app.command("machine")
|
|
2040
2154
|
def agents_machine(
|
|
2041
2155
|
serve: bool = typer.Option(
|
|
@@ -2059,20 +2173,162 @@ def agents_machine(
|
|
|
2059
2173
|
serve_machine(once=once)
|
|
2060
2174
|
|
|
2061
2175
|
|
|
2176
|
+
def _current_messaging() -> Optional[str]:
|
|
2177
|
+
"""This machine's messaging mode, or None on a qbraid-core without modes."""
|
|
2178
|
+
try:
|
|
2179
|
+
from qbraid_core.services.agents import messaging_mode # type: ignore[attr-defined]
|
|
2180
|
+
except ImportError:
|
|
2181
|
+
return None
|
|
2182
|
+
return messaging_mode.machine_mode()
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
def _messaging_kwargs(method: Callable[..., Any], messaging: Optional[str]) -> Dict[str, Any]:
|
|
2186
|
+
"""Forward ``messaging`` only to a qbraid-core that takes it; refuse otherwise.
|
|
2187
|
+
|
|
2188
|
+
Refused rather than dropped: an agent meant to be restricted must not start
|
|
2189
|
+
open because the core is old.
|
|
2190
|
+
"""
|
|
2191
|
+
if messaging is None:
|
|
2192
|
+
return {}
|
|
2193
|
+
try:
|
|
2194
|
+
params = inspect.signature(method).parameters
|
|
2195
|
+
supported = "messaging" in params or any(
|
|
2196
|
+
param.kind is inspect.Parameter.VAR_KEYWORD for param in params.values()
|
|
2197
|
+
)
|
|
2198
|
+
except (TypeError, ValueError): # pragma: no cover - non-introspectable callable
|
|
2199
|
+
supported = True
|
|
2200
|
+
if not supported:
|
|
2201
|
+
console.print(
|
|
2202
|
+
"[red]--messaging needs a newer qbraid-core[/red] (one with messaging modes); "
|
|
2203
|
+
"nothing was launched."
|
|
2204
|
+
)
|
|
2205
|
+
raise typer.Exit(code=1)
|
|
2206
|
+
return {"messaging": messaging}
|
|
2207
|
+
|
|
2208
|
+
|
|
2209
|
+
def _messaging_setting(mode: Optional[str], as_json: bool) -> None:
|
|
2210
|
+
"""Show this machine's messaging mode, or set it (a person only)."""
|
|
2211
|
+
try:
|
|
2212
|
+
# qbraid-core with messaging modes; older ones have only the role rules.
|
|
2213
|
+
from qbraid_core.services.agents import messaging_mode # type: ignore[attr-defined]
|
|
2214
|
+
except ImportError:
|
|
2215
|
+
if mode is not None:
|
|
2216
|
+
console.print("[red]--messaging needs a newer qbraid-core[/red] (one with messaging modes).")
|
|
2217
|
+
raise typer.Exit(code=1) from None
|
|
2218
|
+
return
|
|
2219
|
+
if mode is not None:
|
|
2220
|
+
if mode not in messaging_mode.MODES:
|
|
2221
|
+
console.print("[red]Error:[/red] --messaging is open or restricted.")
|
|
2222
|
+
raise typer.Exit(code=2)
|
|
2223
|
+
try:
|
|
2224
|
+
messaging_mode.set_machine_mode(mode)
|
|
2225
|
+
except messaging_mode.MessagingModeError as err:
|
|
2226
|
+
console.print(f"[red]Not changed:[/red] {_plain(str(err))}")
|
|
2227
|
+
raise typer.Exit(code=1) from None
|
|
2228
|
+
current = messaging_mode.machine_mode()
|
|
2229
|
+
if as_json:
|
|
2230
|
+
print(json.dumps({"messaging": current}))
|
|
2231
|
+
return
|
|
2232
|
+
console.print(f"Messaging: {current} (this machine). " + messaging_mode.describe(None))
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
def _mail_wakes_module():
|
|
2236
|
+
"""qbraid-core's ``mail_wakes`` (#606), or None on an older Core."""
|
|
2237
|
+
try:
|
|
2238
|
+
# pylint: disable-next=import-outside-toplevel
|
|
2239
|
+
from qbraid_core.services.agents import mail_wakes # type: ignore[attr-defined]
|
|
2240
|
+
except ImportError:
|
|
2241
|
+
return None
|
|
2242
|
+
return mail_wakes
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
def _mail_wake_cap_setting(cap: int, as_json: bool) -> None:
|
|
2246
|
+
"""Set this machine's mail wake cap (anyone may lower it; only a person may raise it)."""
|
|
2247
|
+
mail_wakes = _mail_wakes_module()
|
|
2248
|
+
if mail_wakes is None:
|
|
2249
|
+
console.print("[red]--mail-wake-cap needs a newer qbraid-core[/red] (one with mail wakes).")
|
|
2250
|
+
raise typer.Exit(code=1)
|
|
2251
|
+
try:
|
|
2252
|
+
current = mail_wakes.set_wake_cap(cap)
|
|
2253
|
+
except mail_wakes.WakeCapError as err:
|
|
2254
|
+
console.print(f"[red]Not changed:[/red] {_plain(str(err))}")
|
|
2255
|
+
raise typer.Exit(code=1) from None
|
|
2256
|
+
if as_json:
|
|
2257
|
+
print(json.dumps({"mail_wake_cap": current}))
|
|
2258
|
+
return
|
|
2259
|
+
console.print(f"Mail wake cap: {current} (this machine). {_MAIL_WAKE_CAP_NOTE}", soft_wrap=True)
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
#: Said when the cap setting cannot be read (qbraid-core reads it as 0).
|
|
2263
|
+
_CAP_DAMAGED = "cap file damaged; showing 0"
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
def _cap_damaged(mail_wakes) -> bool:
|
|
2267
|
+
"""Whether Core reports the cap setting as damaged (an older Core cannot say)."""
|
|
2268
|
+
check = getattr(mail_wakes, "wake_cap_damaged", None)
|
|
2269
|
+
try:
|
|
2270
|
+
return bool(check()) if callable(check) else False
|
|
2271
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
2272
|
+
return False
|
|
2273
|
+
|
|
2274
|
+
|
|
2275
|
+
#: What the mail wake cap does, for ``settings``.
|
|
2276
|
+
_MAIL_WAKE_CAP_NOTE = (
|
|
2277
|
+
"At most this many mail-triggered wakes per agent per hour with no message from you in "
|
|
2278
|
+
"between; past it, mail waits for your next message to that agent (0: mail never wakes)."
|
|
2279
|
+
)
|
|
2280
|
+
|
|
2281
|
+
|
|
2062
2282
|
@agents_app.command("settings")
|
|
2063
2283
|
def agents_settings(
|
|
2064
2284
|
execution_mode: Optional[ExecutionMode] = typer.Option(
|
|
2065
2285
|
None, "--execution-mode", help="Save the Codex execution default for this machine."
|
|
2066
2286
|
),
|
|
2067
2287
|
reset: bool = typer.Option(False, "--reset", help="Remove this machine's execution preference."),
|
|
2288
|
+
messaging: Optional[MessagingMode] = typer.Option(
|
|
2289
|
+
None,
|
|
2290
|
+
"--messaging",
|
|
2291
|
+
help=(
|
|
2292
|
+
"open (the default): any of your agents may message any other, on any of your machines. "
|
|
2293
|
+
"restricted: the role rules (workers reach their parent, children and team leaders); "
|
|
2294
|
+
"for agents that read untrusted input. Anyone may restrict; only a person may open."
|
|
2295
|
+
),
|
|
2296
|
+
),
|
|
2297
|
+
mail_wake_cap: Optional[int] = typer.Option(
|
|
2298
|
+
None,
|
|
2299
|
+
"--mail-wake-cap",
|
|
2300
|
+
min=0,
|
|
2301
|
+
max=1000,
|
|
2302
|
+
help=(
|
|
2303
|
+
"Mail-triggered wakes per agent per hour with no message from you in between "
|
|
2304
|
+
"(default 20; 0: mail never wakes). Anyone may lower it; only a person may raise it."
|
|
2305
|
+
),
|
|
2306
|
+
),
|
|
2068
2307
|
json_output: bool = typer.Option(
|
|
2069
2308
|
False, "--json", help="Print structured settings and sandbox readiness."
|
|
2070
2309
|
),
|
|
2071
2310
|
):
|
|
2072
|
-
"""
|
|
2311
|
+
"""Configure agent execution and messaging.
|
|
2073
2312
|
|
|
2074
|
-
Defaults are shared by the CLI and dashboard on this machine.
|
|
2313
|
+
Inspect or change them. Defaults are shared by the CLI and dashboard on this machine.
|
|
2075
2314
|
"""
|
|
2315
|
+
if messaging is not None:
|
|
2316
|
+
if reset or execution_mode is not None or mail_wake_cap is not None:
|
|
2317
|
+
console.print(
|
|
2318
|
+
"[red]Error:[/red] Set --messaging on its own (not with --reset, --execution-mode "
|
|
2319
|
+
"or --mail-wake-cap)."
|
|
2320
|
+
)
|
|
2321
|
+
raise typer.Exit(code=2)
|
|
2322
|
+
_messaging_setting(messaging.value, json_output)
|
|
2323
|
+
return
|
|
2324
|
+
if mail_wake_cap is not None:
|
|
2325
|
+
if reset or execution_mode is not None:
|
|
2326
|
+
console.print(
|
|
2327
|
+
"[red]Error:[/red] Set --mail-wake-cap on its own (not with --reset or --execution-mode)."
|
|
2328
|
+
)
|
|
2329
|
+
raise typer.Exit(code=2)
|
|
2330
|
+
_mail_wake_cap_setting(mail_wake_cap, json_output)
|
|
2331
|
+
return
|
|
2076
2332
|
try:
|
|
2077
2333
|
from qbraid_core.services.agents.execution import execution_settings, set_execution_default
|
|
2078
2334
|
|
|
@@ -2084,9 +2340,27 @@ def agents_settings(
|
|
|
2084
2340
|
settings = set_execution_default(execution_mode.value)
|
|
2085
2341
|
else:
|
|
2086
2342
|
settings = execution_settings()
|
|
2343
|
+
current_messaging = _current_messaging()
|
|
2344
|
+
mail_wakes = _mail_wakes_module()
|
|
2345
|
+
cap = mail_wakes.wake_cap() if mail_wakes is not None else None
|
|
2346
|
+
damaged = mail_wakes is not None and _cap_damaged(mail_wakes)
|
|
2087
2347
|
if json_output:
|
|
2088
|
-
print(
|
|
2348
|
+
print(
|
|
2349
|
+
json.dumps(
|
|
2350
|
+
{
|
|
2351
|
+
**settings,
|
|
2352
|
+
**({"messaging": current_messaging} if current_messaging else {}),
|
|
2353
|
+
**({"mail_wake_cap": cap} if cap is not None else {}),
|
|
2354
|
+
**({"mail_wake_cap_damaged": True} if damaged else {}),
|
|
2355
|
+
}
|
|
2356
|
+
)
|
|
2357
|
+
)
|
|
2089
2358
|
else:
|
|
2359
|
+
if current_messaging:
|
|
2360
|
+
console.print(f"Messaging: {current_messaging} (this machine).")
|
|
2361
|
+
if cap is not None:
|
|
2362
|
+
shown = f"{cap} ({_CAP_DAMAGED}; set it again with --mail-wake-cap)" if damaged else cap
|
|
2363
|
+
console.print(f"Mail wake cap: {shown} (this machine). {_MAIL_WAKE_CAP_NOTE}", soft_wrap=True)
|
|
2090
2364
|
console.print(
|
|
2091
2365
|
"Codex execution default: " + (settings["execution_mode"] or "not set (legacy defaults)")
|
|
2092
2366
|
)
|
|
@@ -2488,6 +2762,15 @@ def agents_launch(
|
|
|
2488
2762
|
"decides. yolo: no permission checks. ask/auto: legacy modes, unchanged."
|
|
2489
2763
|
),
|
|
2490
2764
|
),
|
|
2765
|
+
messaging: Optional[MessagingMode] = typer.Option(
|
|
2766
|
+
None,
|
|
2767
|
+
"--messaging",
|
|
2768
|
+
help=(
|
|
2769
|
+
"This agent's messaging: open (it may message any of your agents) or restricted "
|
|
2770
|
+
"(the role rules). Default: the machine's (qbraid agents settings --messaging). "
|
|
2771
|
+
"Anyone may restrict; opening takes a person or a bypass-mode agent."
|
|
2772
|
+
),
|
|
2773
|
+
),
|
|
2491
2774
|
trust_hooks: bool = typer.Option(
|
|
2492
2775
|
False,
|
|
2493
2776
|
"--trust-hooks",
|
|
@@ -2588,6 +2871,7 @@ def agents_launch(
|
|
|
2588
2871
|
raise AgentLauncherError("Remote launches select the backend on the destination; omit --backend.")
|
|
2589
2872
|
launcher = _backend_launcher(backend)
|
|
2590
2873
|
|
|
2874
|
+
messaging_value = messaging.value if messaging is not None else None
|
|
2591
2875
|
# Remote launch via SSH
|
|
2592
2876
|
if compute:
|
|
2593
2877
|
links = _remote_link_kwargs(launcher.remote_launch, team, parent, repo, detached=detached)
|
|
@@ -2605,6 +2889,7 @@ def agents_launch(
|
|
|
2605
2889
|
**_approval_kwargs(launcher.remote_launch, approval.value if approval else None),
|
|
2606
2890
|
**_hook_trust_kwargs(launcher.remote_launch, True if trust_hooks else None),
|
|
2607
2891
|
**_execution_kwargs(launcher.remote_launch, execution_mode.value if execution_mode else None),
|
|
2892
|
+
**_messaging_kwargs(launcher.remote_launch, messaging_value),
|
|
2608
2893
|
)
|
|
2609
2894
|
if links.get("parent_is_default") and not session.parent_session_id:
|
|
2610
2895
|
console.print(
|
|
@@ -2631,6 +2916,7 @@ def agents_launch(
|
|
|
2631
2916
|
**_hook_trust_kwargs(launcher.launch, True if trust_hooks else None),
|
|
2632
2917
|
**_prompt_answer_kwargs(launcher.launch, trust_folder, skip_bypass_confirmation),
|
|
2633
2918
|
**_execution_kwargs(launcher.launch, execution_mode.value if execution_mode else None),
|
|
2919
|
+
**_messaging_kwargs(launcher.launch, messaging_value),
|
|
2634
2920
|
progress_callback=_clone_progress if repo else None,
|
|
2635
2921
|
)
|
|
2636
2922
|
|
|
@@ -2678,6 +2964,10 @@ def agents_launch(
|
|
|
2678
2964
|
except (typer.Exit, SystemExit):
|
|
2679
2965
|
raise
|
|
2680
2966
|
except Exception as e:
|
|
2967
|
+
if _is_messaging_mode_error(e):
|
|
2968
|
+
# e.g. an agent asking to launch an open child: one line, no traceback.
|
|
2969
|
+
console.print(f"[red]Not launched:[/red] {_plain(str(e))}", soft_wrap=True)
|
|
2970
|
+
raise typer.Exit(code=1) from None
|
|
2681
2971
|
handle_error(message=str(e))
|
|
2682
2972
|
raise typer.Exit(code=1)
|
|
2683
2973
|
|
|
@@ -3270,6 +3560,15 @@ def _report_typed(as_json: bool, target: str, compute: Optional[str]) -> None:
|
|
|
3270
3560
|
|
|
3271
3561
|
#: Why mail waits, for a ``held:<CODE>`` that a qBraid bridge (or its absence) reports.
|
|
3272
3562
|
_MAIL_WAITS = {
|
|
3563
|
+
"WAKE_COUNT_BUSY": (
|
|
3564
|
+
"qBraid could not update its mail wake count (busy), so it is not woken yet rather than "
|
|
3565
|
+
"risk passing the cap; it is told once the count can be kept."
|
|
3566
|
+
),
|
|
3567
|
+
"WAKE_CAP": (
|
|
3568
|
+
"the agent has used its mail wake cap (mail-triggered wakes in the last hour with no "
|
|
3569
|
+
"message from the person; qbraid agents settings --mail-wake-cap), so it is not woken "
|
|
3570
|
+
"now; it is told once its count frees up within the hour or the person messages it."
|
|
3571
|
+
),
|
|
3273
3572
|
"NEXT_TURN": "the agent has no qBraid bridge to wake it, so it sees the message on its next turn.",
|
|
3274
3573
|
"BRIDGE_STARTING": (
|
|
3275
3574
|
"the agent's qBraid bridge is still starting; it tells the agent as soon as it runs."
|
|
@@ -3333,6 +3632,13 @@ def _print_nudge(outcome) -> None:
|
|
|
3333
3632
|
)
|
|
3334
3633
|
return
|
|
3335
3634
|
reason = str(outcome or "held:UNKNOWN").split(":", 1)[-1]
|
|
3635
|
+
if reason == "SENDER_CANNOT_WAKE":
|
|
3636
|
+
console.print(
|
|
3637
|
+
f"[yellow]Mail waiting ({_plain(reason)}):[/yellow] the message is in the agent's "
|
|
3638
|
+
f"inbox; {_plain(_sender_cannot_wake_text())}",
|
|
3639
|
+
soft_wrap=True,
|
|
3640
|
+
)
|
|
3641
|
+
return
|
|
3336
3642
|
if reason in _MAIL_WAITS:
|
|
3337
3643
|
console.print(
|
|
3338
3644
|
f"[yellow]Mail waiting ({_plain(reason)}):[/yellow] the message is in the agent's "
|
|
@@ -4671,6 +4977,66 @@ def _parse_target_csv(csv: str, registry) -> list[str]:
|
|
|
4671
4977
|
return resolved
|
|
4672
4978
|
|
|
4673
4979
|
|
|
4980
|
+
#: Why ``send-to`` mail waits for the recipient's next turn (``_waits_for_next_turn``).
|
|
4981
|
+
_WAIT_WHY = {
|
|
4982
|
+
"WAKE_COUNT_BUSY": (
|
|
4983
|
+
"qBraid could not update its mail wake count (busy), so it is not woken yet; it is told "
|
|
4984
|
+
"once the count can be kept."
|
|
4985
|
+
),
|
|
4986
|
+
"WAKE_CAP": (
|
|
4987
|
+
"it has used its mail wake cap (mail-triggered wakes in the last hour with no message from "
|
|
4988
|
+
"the person; qbraid agents settings --mail-wake-cap); it is told once its count frees up "
|
|
4989
|
+
"within the hour or the person messages it."
|
|
4990
|
+
),
|
|
4991
|
+
}
|
|
4992
|
+
|
|
4993
|
+
|
|
4994
|
+
def _mail_wakes_label(wakes) -> Optional[str]:
|
|
4995
|
+
"""whoami's ``mail_wakes`` (qbraid-core #606) as one line, or None."""
|
|
4996
|
+
if not isinstance(wakes, dict) or "count" not in wakes:
|
|
4997
|
+
return None
|
|
4998
|
+
text = f"{wakes.get('count')} of {wakes.get('cap')} in the last hour"
|
|
4999
|
+
if wakes.get("cap_damaged"):
|
|
5000
|
+
text += f" ({_CAP_DAMAGED})"
|
|
5001
|
+
return text + (" (held: mail waits until it frees up or the person writes)" if wakes.get("held") else "")
|
|
5002
|
+
|
|
5003
|
+
|
|
5004
|
+
def _sender_cannot_wake_text() -> str:
|
|
5005
|
+
"""``SENDER_CANNOT_WAKE``'s meaning on the installed Core: since qbraid-core
|
|
5006
|
+
#606 only mail from another machine; before it, a sender that was not the
|
|
5007
|
+
person or a bypass agent they launched."""
|
|
5008
|
+
if _mail_wakes_module() is not None:
|
|
5009
|
+
return (
|
|
5010
|
+
"mail from another machine does not wake an agent in a bypass permission mode; it "
|
|
5011
|
+
"sees the message on its next turn."
|
|
5012
|
+
)
|
|
5013
|
+
return "only the person, or an agent they launched in a bypass mode, can wake it."
|
|
5014
|
+
|
|
5015
|
+
|
|
5016
|
+
def _waits_for_next_turn(registry, msg) -> Optional[str]:
|
|
5017
|
+
"""Why *msg* waits for its recipient's next turn, or None when it may wake.
|
|
5018
|
+
|
|
5019
|
+
``"WAKE_CAP"``: Core held it, the recipient's mail wake cap reached
|
|
5020
|
+
(``AgentMessage.held``, qbraid-core #606; for every recipient).
|
|
5021
|
+
``"SENDER_CANNOT_WAKE"``: an older Core marked it as not waking and its
|
|
5022
|
+
recipient holds such mail (``messaging_mode.holds_for``)."""
|
|
5023
|
+
held = getattr(msg, "held", None)
|
|
5024
|
+
if isinstance(held, str) and held:
|
|
5025
|
+
return held
|
|
5026
|
+
if getattr(msg, "wakes", None) is not False:
|
|
5027
|
+
return None
|
|
5028
|
+
try:
|
|
5029
|
+
# pylint: disable-next=import-outside-toplevel
|
|
5030
|
+
from qbraid_core.services.agents.messaging_mode import holds_for # type: ignore[attr-defined]
|
|
5031
|
+
except ImportError:
|
|
5032
|
+
return None
|
|
5033
|
+
try:
|
|
5034
|
+
recipient = registry.get_session(msg.to_session) if registry is not None else None
|
|
5035
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
5036
|
+
recipient = None # as Core decides: an unknown recipient holds it
|
|
5037
|
+
return "SENDER_CANNOT_WAKE" if recipient is None or holds_for(recipient) else None
|
|
5038
|
+
|
|
5039
|
+
|
|
4674
5040
|
def _deliver_to_many(
|
|
4675
5041
|
targets: list[str],
|
|
4676
5042
|
text: str,
|
|
@@ -4699,6 +5065,7 @@ def _deliver_to_many(
|
|
|
4699
5065
|
delivered: list[tuple[str, str]] = []
|
|
4700
5066
|
failed: list[tuple[str, str]] = []
|
|
4701
5067
|
forwards: dict = {}
|
|
5068
|
+
waits: dict = {}
|
|
4702
5069
|
for target_sid in targets:
|
|
4703
5070
|
try:
|
|
4704
5071
|
msg = send_message(
|
|
@@ -4714,6 +5081,7 @@ def _deliver_to_many(
|
|
|
4714
5081
|
# Older Core has no forwarded_from; newer Core types it Optional[str].
|
|
4715
5082
|
forwarded = getattr(msg, "forwarded_from", None)
|
|
4716
5083
|
forwards[msg.id] = forwarded if isinstance(forwarded, str) else None
|
|
5084
|
+
waits[msg.id] = _waits_for_next_turn(registry, msg)
|
|
4717
5085
|
if isinstance(forwarded, str) and forwarded and not as_json:
|
|
4718
5086
|
old_sid, new_sid = str(forwarded), str(msg.to_session)
|
|
4719
5087
|
console.print(
|
|
@@ -4729,7 +5097,13 @@ def _deliver_to_many(
|
|
|
4729
5097
|
_echo_json(
|
|
4730
5098
|
{
|
|
4731
5099
|
"delivered": [
|
|
4732
|
-
{
|
|
5100
|
+
{
|
|
5101
|
+
"to": sid,
|
|
5102
|
+
"id": mid,
|
|
5103
|
+
"type": message_type,
|
|
5104
|
+
"forwarded_from": forwards.get(mid),
|
|
5105
|
+
**({"held": waits[mid]} if waits.get(mid) else {}),
|
|
5106
|
+
}
|
|
4733
5107
|
for sid, mid in delivered
|
|
4734
5108
|
],
|
|
4735
5109
|
"failed": [{"to": sid, "error": reason} for sid, reason in failed],
|
|
@@ -4743,6 +5117,18 @@ def _deliver_to_many(
|
|
|
4743
5117
|
f"[green]→[/green] Sent to [bold]{_plain(sid)}[/bold] "
|
|
4744
5118
|
f"[dim](id={_plain(mid)}, type={_plain(message_type)})[/dim]"
|
|
4745
5119
|
)
|
|
5120
|
+
if waits.get(mid):
|
|
5121
|
+
reason = str(waits[mid])
|
|
5122
|
+
console.print(
|
|
5123
|
+
f"[dim]It waits for {_plain(sid[:8])}'s next turn ({_plain(reason)}): "
|
|
5124
|
+
+ _plain(
|
|
5125
|
+
_sender_cannot_wake_text()
|
|
5126
|
+
if reason == "SENDER_CANNOT_WAKE"
|
|
5127
|
+
else _WAIT_WHY.get(reason, "it is not woken for it.")
|
|
5128
|
+
)
|
|
5129
|
+
+ "[/dim]",
|
|
5130
|
+
soft_wrap=True,
|
|
5131
|
+
)
|
|
4746
5132
|
for sid, reason in failed_shown:
|
|
4747
5133
|
# soft_wrap: a refusal stays one line, so grep-based checks still match.
|
|
4748
5134
|
console.print(f"[red]✗[/red] [bold]{_plain(sid)}[/bold]: {_plain(reason)}", soft_wrap=True)
|
|
@@ -4952,6 +5338,8 @@ def _send_to( # pylint: disable=too-many-arguments
|
|
|
4952
5338
|
reply_alias: Optional[str],
|
|
4953
5339
|
request_id: Optional[str],
|
|
4954
5340
|
as_json: bool = False,
|
|
5341
|
+
ask: bool = False,
|
|
5342
|
+
reason: str = "",
|
|
4955
5343
|
) -> None:
|
|
4956
5344
|
try:
|
|
4957
5345
|
# pylint: disable-next=import-outside-toplevel,unused-import
|
|
@@ -5019,6 +5407,8 @@ def _send_to( # pylint: disable=too-many-arguments
|
|
|
5019
5407
|
# the resume itself, so the message records where it was addressed
|
|
5020
5408
|
# (forwarded_from) and the "resumed as" note is printed.
|
|
5021
5409
|
to_sid = to
|
|
5410
|
+
if ask and _ask_person(registry, from_sid, to_sid, text, reason, as_json, message_type):
|
|
5411
|
+
return
|
|
5022
5412
|
code = _deliver_to_many(
|
|
5023
5413
|
[to_sid],
|
|
5024
5414
|
text,
|
|
@@ -5033,6 +5423,58 @@ def _send_to( # pylint: disable=too-many-arguments
|
|
|
5033
5423
|
raise typer.Exit(code=code)
|
|
5034
5424
|
|
|
5035
5425
|
|
|
5426
|
+
def _ask_person( # pylint: disable=too-many-arguments
|
|
5427
|
+
registry, from_sid: str, to_sid: str, text: str, reason: str, as_json: bool, message_type: str = "message"
|
|
5428
|
+
) -> bool:
|
|
5429
|
+
"""With ``--ask``: hold the message for a person when the rules refuse it.
|
|
5430
|
+
|
|
5431
|
+
Returns False when the sender may message the target anyway (then it is
|
|
5432
|
+
delivered as usual). Exits 5 once a request is filed, 1 when it cannot be.
|
|
5433
|
+
"""
|
|
5434
|
+
try:
|
|
5435
|
+
# pylint: disable-next=import-outside-toplevel
|
|
5436
|
+
# qbraid-core with message requests (qbraid-core#593); older ones raise ImportError below.
|
|
5437
|
+
from qbraid_core.services.agents.messaging import ( # type: ignore[attr-defined]
|
|
5438
|
+
request_person_approval,
|
|
5439
|
+
)
|
|
5440
|
+
except ImportError:
|
|
5441
|
+
console.print(
|
|
5442
|
+
"[red]--ask needs a newer qbraid-core[/red] (one with message requests). "
|
|
5443
|
+
"Upgrade with: pip install -U qbraid-core"
|
|
5444
|
+
)
|
|
5445
|
+
raise typer.Exit(code=1) from None
|
|
5446
|
+
if from_sid == "person":
|
|
5447
|
+
return False # A person asks no one: the rules for a person apply as usual.
|
|
5448
|
+
try:
|
|
5449
|
+
row = request_person_approval(
|
|
5450
|
+
registry, from_sid, to_sid, text, reason=reason, message_type=message_type
|
|
5451
|
+
)
|
|
5452
|
+
except Exception as err: # pylint: disable=broad-exception-caught
|
|
5453
|
+
if as_json:
|
|
5454
|
+
print(
|
|
5455
|
+
json.dumps(
|
|
5456
|
+
{"error": {"code": getattr(err, "code", "MESSAGE_REQUEST_FAILED"), "message": str(err)}}
|
|
5457
|
+
)
|
|
5458
|
+
)
|
|
5459
|
+
else:
|
|
5460
|
+
console.print(f"[red]Not sent:[/red] {_plain(str(err))}")
|
|
5461
|
+
raise typer.Exit(code=1) from None
|
|
5462
|
+
if row.get("state") == "not_needed":
|
|
5463
|
+
return False
|
|
5464
|
+
if as_json:
|
|
5465
|
+
print(
|
|
5466
|
+
json.dumps(
|
|
5467
|
+
{"requested": {key: row.get(key) for key in ("id", "state", "to_session_id", "created_at")}}
|
|
5468
|
+
)
|
|
5469
|
+
)
|
|
5470
|
+
else:
|
|
5471
|
+
console.print(
|
|
5472
|
+
f"Held for a person to approve (request {row.get('id')}): the Lab's Agents sidebar lists it "
|
|
5473
|
+
"under Message requests. Nothing is delivered until they allow it."
|
|
5474
|
+
)
|
|
5475
|
+
raise typer.Exit(code=5)
|
|
5476
|
+
|
|
5477
|
+
|
|
5036
5478
|
def _bad_alias(alias: str) -> bool:
|
|
5037
5479
|
"""An alias ssh could read as an option, or that is not one word."""
|
|
5038
5480
|
return not alias or alias.startswith("-") or any(char.isspace() for char in alias)
|
|
@@ -5118,6 +5560,21 @@ def agents_send_to( # pylint: disable=too-many-arguments
|
|
|
5118
5560
|
'or {"error": {code, message, request_id}}. Same exit codes.'
|
|
5119
5561
|
),
|
|
5120
5562
|
),
|
|
5563
|
+
ask: bool = typer.Option(
|
|
5564
|
+
False,
|
|
5565
|
+
"--ask",
|
|
5566
|
+
help=(
|
|
5567
|
+
"If the messaging rules do not let you message this agent, hold the exact text "
|
|
5568
|
+
"for a person to approve (Agents sidebar, Message requests) instead of failing. "
|
|
5569
|
+
"Exit 5 while it waits; the sender's inbox is told the outcome. With --json: "
|
|
5570
|
+
'{"requested": {id, state, to_session_id, created_at}}.'
|
|
5571
|
+
),
|
|
5572
|
+
),
|
|
5573
|
+
reason: str = typer.Option(
|
|
5574
|
+
"",
|
|
5575
|
+
"--reason",
|
|
5576
|
+
help="With --ask: one line telling the person why (e.g. 'the person asked us to sync').",
|
|
5577
|
+
),
|
|
5121
5578
|
) -> None:
|
|
5122
5579
|
"""Send a message to another agent's inbox.
|
|
5123
5580
|
|
|
@@ -5134,10 +5591,29 @@ def agents_send_to( # pylint: disable=too-many-arguments
|
|
|
5134
5591
|
(leader/worker/observer/reviewer) apply on both machines; an answer to a
|
|
5135
5592
|
message the other agent sent you is always allowed.
|
|
5136
5593
|
|
|
5594
|
+
``--ask``: when the rules refuse, the text is held for a person to allow
|
|
5595
|
+
once, allow for a while, or deny, in the Lab's Agents sidebar. Nothing is
|
|
5596
|
+
delivered until then; an agent cannot approve its own request.
|
|
5597
|
+
|
|
5137
5598
|
Exit codes: 0 delivered, 1 not delivered, 2 usage error, 3 partial
|
|
5138
5599
|
(broadcast), 4 a cross-machine send whose outcome is unknown: retry with
|
|
5139
|
-
the printed ``--request-id
|
|
5600
|
+
the printed ``--request-id``, 5 held for a person's approval (``--ask``).
|
|
5140
5601
|
"""
|
|
5602
|
+
if ask and (compute or reply):
|
|
5603
|
+
console.print(
|
|
5604
|
+
"[red]Error:[/red] --ask is for agents on this machine; "
|
|
5605
|
+
"it does not combine with --compute or --reply."
|
|
5606
|
+
)
|
|
5607
|
+
raise typer.Exit(code=2)
|
|
5608
|
+
if reason and not ask:
|
|
5609
|
+
console.print("[red]Error:[/red] --reason goes with --ask.")
|
|
5610
|
+
raise typer.Exit(code=2)
|
|
5611
|
+
if ask and no_permission_check:
|
|
5612
|
+
console.print(
|
|
5613
|
+
"[red]Error:[/red] --ask asks a person to let a refused message through; "
|
|
5614
|
+
"it does not combine with --no-permission-check."
|
|
5615
|
+
)
|
|
5616
|
+
raise typer.Exit(code=2)
|
|
5141
5617
|
if reply and text is not None:
|
|
5142
5618
|
console.print("[red]Error:[/red] --reply goes to the message's sender; do not also name a target.")
|
|
5143
5619
|
raise typer.Exit(code=2)
|
|
@@ -5157,6 +5633,8 @@ def agents_send_to( # pylint: disable=too-many-arguments
|
|
|
5157
5633
|
reply_alias=reply_alias,
|
|
5158
5634
|
request_id=request_id,
|
|
5159
5635
|
as_json=as_json,
|
|
5636
|
+
ask=ask,
|
|
5637
|
+
reason=reason,
|
|
5160
5638
|
)
|
|
5161
5639
|
|
|
5162
5640
|
|
|
@@ -5333,16 +5811,42 @@ def _render_messages_table(messages, session_id: str, full_ids: bool = False) ->
|
|
|
5333
5811
|
if machine:
|
|
5334
5812
|
# From another machine: answer with `qbraid agents reply <id>`.
|
|
5335
5813
|
from_display += f" @{machine if full_ids else machine[:8]}"
|
|
5814
|
+
label = _provenance_label(msg)
|
|
5815
|
+
if label:
|
|
5816
|
+
# Core's label on a row of its own, so no message text can draw a
|
|
5817
|
+
# line that passes for it.
|
|
5818
|
+
table.add_row("", "", "", "", f"[dim]{_plain(_printable(label))}[/dim]")
|
|
5336
5819
|
table.add_row(
|
|
5337
5820
|
ts,
|
|
5338
|
-
_plain(from_display),
|
|
5821
|
+
_plain(_printable(from_display)),
|
|
5339
5822
|
_plain(msg.type.value),
|
|
5340
5823
|
read_marker,
|
|
5341
|
-
_plain(msg.text),
|
|
5824
|
+
_plain(_printable(msg.text)),
|
|
5342
5825
|
)
|
|
5343
5826
|
console.print(table)
|
|
5344
5827
|
|
|
5345
5828
|
|
|
5829
|
+
def _printable(value) -> str:
|
|
5830
|
+
"""*value* without terminal control characters (ESC sequences could move
|
|
5831
|
+
the cursor and redraw rows above); tabs and new lines are kept."""
|
|
5832
|
+
import unicodedata # pylint: disable=import-outside-toplevel
|
|
5833
|
+
|
|
5834
|
+
return "".join(ch for ch in str(value) if ch in "\n\t" or unicodedata.category(ch) not in ("Cc", "Cf"))
|
|
5835
|
+
|
|
5836
|
+
|
|
5837
|
+
def _provenance_label(msg) -> Optional[str]:
|
|
5838
|
+
"""Core's one-line label of who sent *msg* (qbraid-core #606), or None on an older Core."""
|
|
5839
|
+
try:
|
|
5840
|
+
# pylint: disable-next=import-outside-toplevel
|
|
5841
|
+
from qbraid_core.services.agents.mail_wakes import provenance_label # type: ignore
|
|
5842
|
+
except ImportError:
|
|
5843
|
+
return None
|
|
5844
|
+
try:
|
|
5845
|
+
return provenance_label(msg)
|
|
5846
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
5847
|
+
return None
|
|
5848
|
+
|
|
5849
|
+
|
|
5346
5850
|
def _runs_in_agent(registry) -> bool:
|
|
5347
5851
|
"""Whether this command runs inside an agent session rather than for the person.
|
|
5348
5852
|
|
|
@@ -5821,9 +6325,9 @@ def agents_nudge_clear(
|
|
|
5821
6325
|
target = _resolve_session_id(session_id, registry=registry)
|
|
5822
6326
|
else:
|
|
5823
6327
|
whoami = _core_messaging_function("whoami", "qbraid agents nudge-clear")
|
|
5824
|
-
target = (whoami(session_id=None, registry=registry) or {}).get(
|
|
6328
|
+
target = (whoami(session_id=None, registry=registry) or {}).get(
|
|
5825
6329
|
"session_id"
|
|
5826
|
-
)
|
|
6330
|
+
) # pylint: disable=not-callable
|
|
5827
6331
|
if not target:
|
|
5828
6332
|
console.print("[red]Not inside an agent session: name the session to clear.[/red]")
|
|
5829
6333
|
raise typer.Exit(code=2)
|
|
@@ -5885,6 +6389,7 @@ def agents_whoami(
|
|
|
5885
6389
|
("Canonical id", info.get("canonical_session_id")),
|
|
5886
6390
|
("Resumed from", info.get("resumed_from")),
|
|
5887
6391
|
("Mail waiting", _held_label(info.get("nudges_held"))),
|
|
6392
|
+
("Mail wakes", _mail_wakes_label(info.get("mail_wakes"))),
|
|
5888
6393
|
(
|
|
5889
6394
|
"Nudge left",
|
|
5890
6395
|
(
|
|
@@ -5894,6 +6399,7 @@ def agents_whoami(
|
|
|
5894
6399
|
),
|
|
5895
6400
|
),
|
|
5896
6401
|
("Rule", info.get("message_rule")),
|
|
6402
|
+
("Messaging", info.get("messaging_note") or info.get("messaging")),
|
|
5897
6403
|
]
|
|
5898
6404
|
if not info.get("registered"):
|
|
5899
6405
|
rows.append(("Registered", "no (not in this host's registry)"))
|
|
@@ -14,8 +14,11 @@ Going through ``qbraid_cli.main`` would import every command group in the CLI
|
|
|
14
14
|
— more to the point — keeps this path from getting slower every time a new
|
|
15
15
|
command group is added.
|
|
16
16
|
|
|
17
|
-
Deliberately has no argument
|
|
18
|
-
so an agent reading stdout can never pick up a stray banner or
|
|
17
|
+
Deliberately has no argument parser: it prints the credential and nothing else,
|
|
18
|
+
so an agent reading stdout can never pick up a stray banner, usage text or
|
|
19
|
+
prompt. The one argument it reads, ``--qbraid-gateway=<url>``, is the agent's
|
|
20
|
+
own gateway, which ``qbraid ai connect`` writes into the helper command; any
|
|
21
|
+
other argument is ignored.
|
|
19
22
|
|
|
20
23
|
The credential is written to the binary stdout buffer rather than via ``print``
|
|
21
24
|
so the bytes are identical on every platform. Text-mode stdout on Windows
|
|
@@ -25,6 +28,8 @@ to the credential an agent reads.
|
|
|
25
28
|
|
|
26
29
|
import sys
|
|
27
30
|
|
|
31
|
+
_GATEWAY_FLAG = "--qbraid-gateway="
|
|
32
|
+
|
|
28
33
|
|
|
29
34
|
def _emit(credential: str) -> None:
|
|
30
35
|
"""Write the credential and exactly one newline, byte-for-byte.
|
|
@@ -43,6 +48,22 @@ def _emit(credential: str) -> None:
|
|
|
43
48
|
buffer.flush()
|
|
44
49
|
|
|
45
50
|
|
|
51
|
+
def _gateway_url(argv: list[str]) -> str:
|
|
52
|
+
"""The agent's gateway from ``--qbraid-gateway=<url>``, or "" when absent.
|
|
53
|
+
|
|
54
|
+
Read here rather than left to Core's ``sys.argv`` fallback, which only
|
|
55
|
+
applies when the program is named ``qbraid-ai-token``: run as
|
|
56
|
+
``python -m qbraid_cli.ai.token`` or through a differently named link, the
|
|
57
|
+
helper would otherwise not count as bound to a gateway (#433). An empty
|
|
58
|
+
value means a helper written by an earlier connect, which Core treats as
|
|
59
|
+
bound to another gateway (fails closed).
|
|
60
|
+
"""
|
|
61
|
+
return next(
|
|
62
|
+
(arg[len(_GATEWAY_FLAG) :] for arg in argv if arg.startswith(_GATEWAY_FLAG)),
|
|
63
|
+
"",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
46
67
|
def main() -> int:
|
|
47
68
|
"""Print the credential, or explain on stderr why there isn't one."""
|
|
48
69
|
try:
|
|
@@ -52,7 +73,7 @@ def main() -> int:
|
|
|
52
73
|
return 1
|
|
53
74
|
|
|
54
75
|
try:
|
|
55
|
-
credential, _ = resolve_credential()
|
|
76
|
+
credential, _ = resolve_credential(gateway_url=_gateway_url(sys.argv[1:]))
|
|
56
77
|
except AiGatewayError as err:
|
|
57
78
|
# stderr only — a failure must never look like a token on stdout.
|
|
58
79
|
print(str(err), file=sys.stderr)
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
"""Local environment registry management CLI commands."""
|
|
5
5
|
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import Optional
|
|
7
|
+
from typing import Callable, Optional
|
|
8
8
|
|
|
9
9
|
import typer
|
|
10
10
|
from rich.console import Console
|
|
11
11
|
|
|
12
|
-
from qbraid_cli.handlers import handle_error, run_progress_task
|
|
12
|
+
from qbraid_cli.handlers import handle_error, require_tty, run_progress_task
|
|
13
13
|
|
|
14
14
|
registry_app = typer.Typer(
|
|
15
15
|
help="Manage the local environment registry.",
|
|
@@ -46,19 +46,23 @@ def registry_add(
|
|
|
46
46
|
|
|
47
47
|
# Get info first to show user
|
|
48
48
|
try:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
# Never run the env's interpreter here: that would run an untrusted env's code
|
|
50
|
+
# before the user has confirmed anything. Core's find_env_python is the rule
|
|
51
|
+
# core registers with; the fallback copies it for qbraid-core 0.6.55.
|
|
52
|
+
from qbraid_core.system import executables
|
|
53
|
+
|
|
54
|
+
def _fallback_find_env_python(env_path: Path) -> Optional[Path]:
|
|
55
|
+
candidates = (
|
|
56
|
+
env_path / "bin" / "python",
|
|
57
|
+
env_path / "bin" / "python3",
|
|
58
|
+
env_path / "Scripts" / "python.exe",
|
|
59
|
+
)
|
|
60
|
+
return next((c for c in candidates if executables.is_exe(c)), None)
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
break
|
|
62
|
+
find_env_python: Callable[[Path], Optional[Path]] = getattr(
|
|
63
|
+
executables, "find_env_python", _fallback_find_env_python
|
|
64
|
+
)
|
|
65
|
+
python_path = find_env_python(path)
|
|
62
66
|
|
|
63
67
|
if not python_path:
|
|
64
68
|
handle_error(
|
|
@@ -69,10 +73,18 @@ def registry_add(
|
|
|
69
73
|
|
|
70
74
|
# Confirm with user
|
|
71
75
|
if not auto_confirm:
|
|
76
|
+
require_tty(
|
|
77
|
+
"qbraid envs registry add",
|
|
78
|
+
"confirmation required",
|
|
79
|
+
"Re-run with --yes.",
|
|
80
|
+
)
|
|
72
81
|
console.print("\n[bold]📦 Registering external environment:[/bold]")
|
|
73
82
|
console.print(f" Path: {path}")
|
|
74
83
|
console.print(f" Name: {alias or name or path.name}")
|
|
75
84
|
console.print(f" Python: {python_path}")
|
|
85
|
+
console.print(
|
|
86
|
+
" Registering runs this interpreter (python -m pip freeze) to record its packages."
|
|
87
|
+
)
|
|
76
88
|
|
|
77
89
|
if not typer.confirm("\nProceed with registration?"):
|
|
78
90
|
typer.echo("❌ Registration cancelled.")
|
|
@@ -90,6 +102,8 @@ def registry_add(
|
|
|
90
102
|
typer.echo(f" - Add kernel: qbraid kernels add {result['name']}")
|
|
91
103
|
typer.echo(" - View in list: qbraid envs list")
|
|
92
104
|
|
|
105
|
+
except typer.Exit:
|
|
106
|
+
raise
|
|
93
107
|
except Exception as e:
|
|
94
108
|
handle_error(message=str(e))
|
|
95
109
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qbraid-cli
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.2
|
|
4
4
|
Summary: Command Line Interface for interacting with all parts of the qBraid platform.
|
|
5
5
|
Author-email: qBraid Development Team <contact@qbraid.com>
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -30,11 +30,11 @@ Requires-Dist: typer>=0.12.1
|
|
|
30
30
|
Requires-Dist: rich>=10.11.0
|
|
31
31
|
Requires-Dist: click<=8.5.1
|
|
32
32
|
Requires-Dist: questionary>=2.0.0
|
|
33
|
-
Requires-Dist: qbraid-core>=0.6.
|
|
33
|
+
Requires-Dist: qbraid-core>=0.6.56
|
|
34
34
|
Provides-Extra: compute
|
|
35
|
-
Requires-Dist: qbraid-core[compute]>=0.6.
|
|
35
|
+
Requires-Dist: qbraid-core[compute]>=0.6.56; extra == "compute"
|
|
36
36
|
Provides-Extra: envs
|
|
37
|
-
Requires-Dist: qbraid-core[environments]>=0.6.
|
|
37
|
+
Requires-Dist: qbraid-core[environments]>=0.6.56; extra == "envs"
|
|
38
38
|
Provides-Extra: dev
|
|
39
39
|
Requires-Dist: isort; extra == "dev"
|
|
40
40
|
Requires-Dist: black; extra == "dev"
|
|
@@ -2,10 +2,10 @@ typer>=0.12.1
|
|
|
2
2
|
rich>=10.11.0
|
|
3
3
|
click<=8.5.1
|
|
4
4
|
questionary>=2.0.0
|
|
5
|
-
qbraid-core>=0.6.
|
|
5
|
+
qbraid-core>=0.6.56
|
|
6
6
|
|
|
7
7
|
[compute]
|
|
8
|
-
qbraid-core[compute]>=0.6.
|
|
8
|
+
qbraid-core[compute]>=0.6.56
|
|
9
9
|
|
|
10
10
|
[dev]
|
|
11
11
|
isort
|
|
@@ -15,4 +15,4 @@ pytest-cov
|
|
|
15
15
|
pytest-asyncio
|
|
16
16
|
|
|
17
17
|
[envs]
|
|
18
|
-
qbraid-core[environments]>=0.6.
|
|
18
|
+
qbraid-core[environments]>=0.6.56
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|