qbraid-cli 0.16.17__tar.gz → 0.16.18__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.16.17/qbraid_cli.egg-info → qbraid_cli-0.16.18}/PKG-INFO +4 -4
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/pyproject.toml +4 -4
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/app.py +529 -37
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18/qbraid_cli.egg-info}/PKG-INFO +4 -4
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli.egg-info/requires.txt +3 -3
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/LICENSE +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/README.md +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/_build_info.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/_version.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/account/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/account/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/admin/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/admin/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/admin/headers.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/admin/validation.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/keep_alive.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/permission_response.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/provider_children.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/queue.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/agents/work.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/ai/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/ai/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/ai/token.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/artifacts/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/artifacts/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/comms/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/comms/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/instances.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/profiles.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/server.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/compute/ssh.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/configure/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/configure/actions.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/configure/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/devices/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/devices/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/devices/validation.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/activate.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/create.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/data_handling.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/groups.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/publish.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/registry.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/envs/share.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/exceptions.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/handlers.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/jobs/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/jobs/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/jobs/groups.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/kernels/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/kernels/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/lab/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/lab/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/main.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/pip/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/pip/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/pip/hooks.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/projects/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/projects/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/py.typed +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/skills/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/skills/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/troubleshoot/__init__.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli/troubleshoot/app.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli.egg-info/SOURCES.txt +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli.egg-info/dependency_links.txt +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli.egg-info/entry_points.txt +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/qbraid_cli.egg-info/top_level.txt +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/setup.cfg +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/tests/test_cli_e2e.py +0 -0
- {qbraid_cli-0.16.17 → qbraid_cli-0.16.18}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qbraid-cli
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.18
|
|
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.0
|
|
32
32
|
Requires-Dist: questionary>=2.0.0
|
|
33
|
-
Requires-Dist: qbraid-core>=0.6.
|
|
33
|
+
Requires-Dist: qbraid-core>=0.6.45
|
|
34
34
|
Provides-Extra: compute
|
|
35
|
-
Requires-Dist: qbraid-core[compute]>=0.6.
|
|
35
|
+
Requires-Dist: qbraid-core[compute]>=0.6.45; extra == "compute"
|
|
36
36
|
Provides-Extra: envs
|
|
37
|
-
Requires-Dist: qbraid-core[environments]>=0.6.
|
|
37
|
+
Requires-Dist: qbraid-core[environments]>=0.6.45; 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.16.
|
|
7
|
+
version = "0.16.18"
|
|
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.0",
|
|
34
34
|
"questionary>=2.0.0",
|
|
35
|
-
"qbraid-core>=0.6.
|
|
35
|
+
"qbraid-core>=0.6.45",
|
|
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.45"]
|
|
47
|
+
envs = ["qbraid-core[environments]>=0.6.45"]
|
|
48
48
|
dev = ["isort", "black", "pytest", "pytest-cov", "pytest-asyncio"]
|
|
49
49
|
|
|
50
50
|
[project.scripts]
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import errno
|
|
7
7
|
import inspect
|
|
8
8
|
import json
|
|
9
|
+
import math
|
|
9
10
|
import os
|
|
10
11
|
import re
|
|
11
12
|
import signal
|
|
@@ -47,7 +48,11 @@ agents_app = typer.Typer(
|
|
|
47
48
|
" qbraid agents launch # Interactive launch\n"
|
|
48
49
|
" qbraid agents list # Show active sessions\n"
|
|
49
50
|
" qbraid agents watch <name> # Stream live activity\n"
|
|
50
|
-
' qbraid agents send <name> --text "..." # Send instructions'
|
|
51
|
+
' qbraid agents send <name> --text "..." # Send instructions\n\n'
|
|
52
|
+
"Agent-to-agent messaging (same host):\n"
|
|
53
|
+
" qbraid agents whoami --json # Who am I, who may I message\n"
|
|
54
|
+
" qbraid agents inbox --unread --json # Full messages, not marked read\n"
|
|
55
|
+
" qbraid agents wait --timeout 600 --json # Block for the next message"
|
|
51
56
|
),
|
|
52
57
|
no_args_is_help=True,
|
|
53
58
|
)
|
|
@@ -232,7 +237,7 @@ def _core_method(registry, name: str):
|
|
|
232
237
|
return getattr(registry, name)
|
|
233
238
|
|
|
234
239
|
|
|
235
|
-
def _calling_session(registry) -> Optional[str]:
|
|
240
|
+
def _calling_session(registry, refuse_ambiguous: bool = True) -> Optional[str]:
|
|
236
241
|
"""The live agent session this command runs inside, if any.
|
|
237
242
|
|
|
238
243
|
Newer qbraid-core finds it by process ancestry, so unsetting
|
|
@@ -247,6 +252,8 @@ def _calling_session(registry) -> Optional[str]:
|
|
|
247
252
|
return find()
|
|
248
253
|
except Exception as err: # pylint: disable=broad-exception-caught
|
|
249
254
|
if _is_registry_error(err):
|
|
255
|
+
if not refuse_ambiguous:
|
|
256
|
+
return None
|
|
250
257
|
# Core could not tell which agent this is (for example, the
|
|
251
258
|
# caller matches more than one live session). Refuse rather
|
|
252
259
|
# than fail open to "the person".
|
|
@@ -2192,6 +2199,25 @@ def _startup_notice(session, compute=None):
|
|
|
2192
2199
|
console.print(f" qbraid agents attach {shlex.quote(session.session_id)}{suffix}", markup=False)
|
|
2193
2200
|
|
|
2194
2201
|
|
|
2202
|
+
def _default_launch_parent(parent: Optional[str]) -> Optional[str]:
|
|
2203
|
+
"""The parent recorded for a local launch.
|
|
2204
|
+
|
|
2205
|
+
An explicit --parent is kept ('' or --detached means none). Otherwise an
|
|
2206
|
+
agent that launches another becomes its parent, so the parent/child
|
|
2207
|
+
messaging rule (one level: direct parent and direct children only) lets
|
|
2208
|
+
it follow up; a person (no calling agent session) records no parent. The
|
|
2209
|
+
launcher's team is never copied to the child. The parent link is registry metadata only. A caller
|
|
2210
|
+
the registry cannot tell apart, or any lookup failure, records no parent
|
|
2211
|
+
rather than failing the launch.
|
|
2212
|
+
"""
|
|
2213
|
+
if parent is not None:
|
|
2214
|
+
return parent or None
|
|
2215
|
+
try:
|
|
2216
|
+
return _calling_session(_get_registry(), refuse_ambiguous=False)
|
|
2217
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
2218
|
+
return None
|
|
2219
|
+
|
|
2220
|
+
|
|
2195
2221
|
@agents_app.command("launch")
|
|
2196
2222
|
def agents_launch(
|
|
2197
2223
|
backend: TerminalBackend = typer.Option(
|
|
@@ -2211,8 +2237,26 @@ def agents_launch(
|
|
|
2211
2237
|
agent_type: Optional[str] = typer.Option(
|
|
2212
2238
|
None, "--type", help="Agent type: leader, worker, observer, reviewer"
|
|
2213
2239
|
),
|
|
2214
|
-
parent: Optional[str] = typer.Option(
|
|
2215
|
-
|
|
2240
|
+
parent: Optional[str] = typer.Option(
|
|
2241
|
+
None,
|
|
2242
|
+
"--parent",
|
|
2243
|
+
help=(
|
|
2244
|
+
"Parent session ID. When an agent launches another agent, the launcher "
|
|
2245
|
+
"becomes its parent by default; parent and child can message each other "
|
|
2246
|
+
"(one level only). '' or --detached for none."
|
|
2247
|
+
),
|
|
2248
|
+
),
|
|
2249
|
+
detached: bool = typer.Option(
|
|
2250
|
+
False,
|
|
2251
|
+
"--detached",
|
|
2252
|
+
help=(
|
|
2253
|
+
"Launch an independent agent with no parent link (same as --parent ''). "
|
|
2254
|
+
"Cannot be combined with --parent."
|
|
2255
|
+
),
|
|
2256
|
+
),
|
|
2257
|
+
team: Optional[str] = typer.Option(
|
|
2258
|
+
None, "--team", help="Team ID. Teams are never inherited from the launcher."
|
|
2259
|
+
),
|
|
2216
2260
|
tag: Optional[List[str]] = typer.Option(None, "--tag", help="Tags (repeatable)"),
|
|
2217
2261
|
compute: Optional[str] = typer.Option(
|
|
2218
2262
|
None, "--compute", "-c", help="SSH alias for remote compute server"
|
|
@@ -2274,7 +2318,17 @@ def agents_launch(
|
|
|
2274
2318
|
--approval auto disables approval prompts; --execution-mode container
|
|
2275
2319
|
explicitly uses the current user's access without an extra Codex sandbox.
|
|
2276
2320
|
Choose it only where you trust the surrounding machine/container isolation.
|
|
2321
|
+
|
|
2322
|
+
When an agent launches another agent, the launcher becomes its parent;
|
|
2323
|
+
parent and child can message each other (one level only). Use --detached
|
|
2324
|
+
for an independent agent. Teams are never inherited. A person launching
|
|
2325
|
+
from their own terminal sets no parent.
|
|
2277
2326
|
"""
|
|
2327
|
+
if detached and parent:
|
|
2328
|
+
console.print("[red]Error:[/red] --detached and --parent cannot be combined.")
|
|
2329
|
+
raise typer.Exit(code=2)
|
|
2330
|
+
if detached:
|
|
2331
|
+
parent = ""
|
|
2278
2332
|
try:
|
|
2279
2333
|
from qbraid_core.services.agents import AgentLauncherError
|
|
2280
2334
|
|
|
@@ -2355,7 +2409,7 @@ def agents_launch(
|
|
|
2355
2409
|
instructions=instructions,
|
|
2356
2410
|
repo=repo,
|
|
2357
2411
|
agent_type=agent_type,
|
|
2358
|
-
parent_session_id=parent,
|
|
2412
|
+
parent_session_id=_default_launch_parent(parent),
|
|
2359
2413
|
team_id=team,
|
|
2360
2414
|
tags=tag,
|
|
2361
2415
|
**_approval_kwargs(launcher.launch, approval.value if approval else None),
|
|
@@ -2815,8 +2869,25 @@ def agents_send(
|
|
|
2815
2869
|
session_id: str = typer.Argument(..., help="Session ID (prefix match)"),
|
|
2816
2870
|
text: str = typer.Option(..., "--text", "-m", help="Text to send"),
|
|
2817
2871
|
compute: Optional[str] = typer.Option(None, "--compute", "-c", help="SSH alias for remote compute"),
|
|
2872
|
+
no_permission_check: bool = typer.Option(
|
|
2873
|
+
False,
|
|
2874
|
+
"--no-permission-check",
|
|
2875
|
+
help="Skip the sender→target permission check, as on send-to. Use for testing.",
|
|
2876
|
+
),
|
|
2818
2877
|
):
|
|
2819
|
-
"""Send text to a running agent's terminal.
|
|
2878
|
+
"""Send text to a running agent's terminal.
|
|
2879
|
+
|
|
2880
|
+
Typed input is a message too, so an agent sending it is held to the same
|
|
2881
|
+
permission rules as ``qbraid agents send-to`` (and refused with the same
|
|
2882
|
+
list of sessions it may message). The sender is the agent session this
|
|
2883
|
+
command runs inside; outside any agent session (no live
|
|
2884
|
+
``QBRAID_SESSION_ID``) the sender is the person, who may type into any
|
|
2885
|
+
session. A sender with no agent type (a hand-started or legacy session)
|
|
2886
|
+
is not checked, and an agent may always type into the agents it launched
|
|
2887
|
+
(``launch`` records the caller as their parent). With ``--compute`` the
|
|
2888
|
+
target lives on another host, whose registry does not know the sender, so
|
|
2889
|
+
no permission check applies there.
|
|
2890
|
+
"""
|
|
2820
2891
|
try:
|
|
2821
2892
|
# Imported before anything else in this try: the `except
|
|
2822
2893
|
# AgentLauncherError` clause below cannot be evaluated unless the name
|
|
@@ -2831,8 +2902,12 @@ def agents_send(
|
|
|
2831
2902
|
console.print(f"[green]Sent text to session {session_id} on {compute}.[/green]")
|
|
2832
2903
|
return
|
|
2833
2904
|
|
|
2905
|
+
target_id = None if no_permission_check else _check_send_permission(session_id)
|
|
2906
|
+
|
|
2834
2907
|
launcher = AgentLauncher()
|
|
2835
|
-
|
|
2908
|
+
# An agent's text goes to the very session the check resolved; the
|
|
2909
|
+
# launcher's resolver ranks ids and names differently.
|
|
2910
|
+
launcher.send(target_id or session_id, text)
|
|
2836
2911
|
console.print(f"[green]Sent text to session {session_id}.[/green]")
|
|
2837
2912
|
|
|
2838
2913
|
except (AgentLauncherError,) as e:
|
|
@@ -2845,6 +2920,82 @@ def agents_send(
|
|
|
2845
2920
|
raise typer.Exit(code=1)
|
|
2846
2921
|
|
|
2847
2922
|
|
|
2923
|
+
def _check_send_permission(identifier: str) -> Optional[str]:
|
|
2924
|
+
"""Refuse an agent typing into a session it may not message (exit 1).
|
|
2925
|
+
|
|
2926
|
+
Returns the resolved target session id when the sender is an agent, so
|
|
2927
|
+
the caller types into exactly the session that was checked; None for the
|
|
2928
|
+
person (no calling agent session), who is never refused and keeps the
|
|
2929
|
+
launcher's own resolution. A sender with no agent type (a legacy or
|
|
2930
|
+
hand-started session that never joined the team model) is not refused
|
|
2931
|
+
either, unlike on ``send-to``. Deliberately: typing into a pane is how
|
|
2932
|
+
such a session drives the agents it started, and those started before
|
|
2933
|
+
``launch`` recorded a parent (or from the Lab, which records none) have
|
|
2934
|
+
no parent link, so the send-to rule would refuse them. Inbox delivery
|
|
2935
|
+
had no such established use, so send-to keeps the strict rule. A sender
|
|
2936
|
+
the registry cannot look up (an unregistered id from the environment, or
|
|
2937
|
+
an older Core) is treated the same way, as untyped.
|
|
2938
|
+
"""
|
|
2939
|
+
registry = _get_registry()
|
|
2940
|
+
sender = _calling_session(registry)
|
|
2941
|
+
if not sender:
|
|
2942
|
+
return None
|
|
2943
|
+
target = _find_session_by_prefix(registry, identifier)
|
|
2944
|
+
if target is None:
|
|
2945
|
+
console.print(
|
|
2946
|
+
f"[red]No session matched '{_plain(identifier)}'.[/red] "
|
|
2947
|
+
"Try 'qbraid agents list' to see available sessions."
|
|
2948
|
+
)
|
|
2949
|
+
raise typer.Exit(code=1)
|
|
2950
|
+
if target.session_id == sender:
|
|
2951
|
+
return target.session_id
|
|
2952
|
+
try:
|
|
2953
|
+
sender_type = registry.get_session(sender).agent_type
|
|
2954
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
2955
|
+
sender_type = None
|
|
2956
|
+
if not sender_type:
|
|
2957
|
+
return target.session_id
|
|
2958
|
+
reason = _permission_refusal(registry, sender, target.session_id)
|
|
2959
|
+
if reason:
|
|
2960
|
+
console.print(
|
|
2961
|
+
f"[red]✗[/red] [bold]{_plain(target.session_id)}[/bold]: {_plain(reason)}", soft_wrap=True
|
|
2962
|
+
)
|
|
2963
|
+
raise typer.Exit(code=1)
|
|
2964
|
+
return target.session_id
|
|
2965
|
+
|
|
2966
|
+
|
|
2967
|
+
def _permission_refusal(registry, from_sid: str, to_sid: str) -> Optional[str]:
|
|
2968
|
+
"""Why ``from_sid`` may not message ``to_sid``, or None.
|
|
2969
|
+
|
|
2970
|
+
Core's ``permission_refusal`` names the rule and the allowed recipients;
|
|
2971
|
+
an older Core (no such function) gets the same matrix through
|
|
2972
|
+
``can_message`` with a shorter reason.
|
|
2973
|
+
"""
|
|
2974
|
+
# pylint: disable-next=import-outside-toplevel
|
|
2975
|
+
from qbraid_core.services.agents import messaging as core_messaging
|
|
2976
|
+
|
|
2977
|
+
refusal = getattr(core_messaging, "permission_refusal", None)
|
|
2978
|
+
if callable(refusal):
|
|
2979
|
+
return refusal(registry, from_sid, to_sid) # pylint: disable=not-callable
|
|
2980
|
+
|
|
2981
|
+
# pylint: disable-next=import-outside-toplevel
|
|
2982
|
+
from qbraid_core.services.agents.types import can_message
|
|
2983
|
+
|
|
2984
|
+
try:
|
|
2985
|
+
sender = registry.get_session(from_sid)
|
|
2986
|
+
target = registry.get_session(to_sid)
|
|
2987
|
+
except Exception as err: # pylint: disable=broad-exception-caught
|
|
2988
|
+
return f"Cannot resolve sessions for permission check: {err}"
|
|
2989
|
+
sender_type = sender.agent_type or "worker"
|
|
2990
|
+
target_type = target.agent_type or "worker"
|
|
2991
|
+
same_team = bool(sender.team_id) and sender.team_id == target.team_id
|
|
2992
|
+
is_parent = sender.parent_session_id == to_sid
|
|
2993
|
+
is_child = target.parent_session_id == from_sid or to_sid in (sender.child_session_ids or [])
|
|
2994
|
+
if can_message(sender_type, target_type, same_team=same_team, is_parent=is_parent, is_child=is_child):
|
|
2995
|
+
return None
|
|
2996
|
+
return f"Agent type '{sender_type}' is not permitted to message agent type '{target_type}'"
|
|
2997
|
+
|
|
2998
|
+
|
|
2848
2999
|
# =============================================================================
|
|
2849
3000
|
# Read command
|
|
2850
3001
|
# =============================================================================
|
|
@@ -3773,25 +3924,31 @@ def _resolve_from_session(explicit: Optional[str], registry=None) -> str:
|
|
|
3773
3924
|
def _resolve_session_id(
|
|
3774
3925
|
explicit: Optional[str], registry=None, allow_missing_in_registry: bool = True
|
|
3775
3926
|
) -> str:
|
|
3776
|
-
"""Determine which session to operate on (
|
|
3927
|
+
"""Determine which session to operate on (inbox, inbox mark-read, wait).
|
|
3777
3928
|
|
|
3778
3929
|
Priority:
|
|
3779
3930
|
1. ``explicit`` (from --session): full id, prefix, or tmux/terminal name.
|
|
3780
3931
|
Resolved via the registry so prefixes and names work (fixes Persona A's
|
|
3781
3932
|
"``inbox --session <prefix>`` returned empty" finding).
|
|
3782
|
-
2.
|
|
3783
|
-
|
|
3933
|
+
2. The agent session this command runs inside, found the way send,
|
|
3934
|
+
send-to and whoami find it (process ancestry, then a live
|
|
3935
|
+
``$QBRAID_SESSION_ID``). A caller that fits several sessions is
|
|
3936
|
+
refused, as on send-to.
|
|
3937
|
+
3. ``$QBRAID_SESSION_ID`` as given, so an inbox that outlived its
|
|
3938
|
+
session stays readable.
|
|
3939
|
+
4. Fail with a helpful error.
|
|
3784
3940
|
|
|
3785
3941
|
When ``allow_missing_in_registry`` is True (the default for inbox ops),
|
|
3786
3942
|
a name/prefix that doesn't resolve is returned as-is — the inbox file
|
|
3787
3943
|
might still exist even if the registry entry has been pruned. This
|
|
3788
3944
|
preserves the "list old inbox that outlived its session" case.
|
|
3789
3945
|
"""
|
|
3946
|
+
if registry is None:
|
|
3947
|
+
registry = _get_registry()
|
|
3790
3948
|
if explicit:
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
return match.session_id
|
|
3949
|
+
match = _find_session_by_prefix(registry, explicit)
|
|
3950
|
+
if match is not None:
|
|
3951
|
+
return match.session_id
|
|
3795
3952
|
if allow_missing_in_registry:
|
|
3796
3953
|
return explicit
|
|
3797
3954
|
console.print(
|
|
@@ -3800,6 +3957,9 @@ def _resolve_session_id(
|
|
|
3800
3957
|
)
|
|
3801
3958
|
raise typer.Exit(code=1)
|
|
3802
3959
|
|
|
3960
|
+
caller = _calling_session(registry)
|
|
3961
|
+
if caller:
|
|
3962
|
+
return caller
|
|
3803
3963
|
env_sid = os.environ.get("QBRAID_SESSION_ID")
|
|
3804
3964
|
if env_sid:
|
|
3805
3965
|
return env_sid
|
|
@@ -3933,7 +4093,8 @@ def _deliver_to_many(
|
|
|
3933
4093
|
f"[dim](id={_plain(mid)}, type={_plain(message_type)})[/dim]"
|
|
3934
4094
|
)
|
|
3935
4095
|
for sid, reason in failed:
|
|
3936
|
-
|
|
4096
|
+
# soft_wrap: a refusal stays one line, so grep-based checks still match.
|
|
4097
|
+
console.print(f"[red]✗[/red] [bold]{_plain(sid)}[/bold]: {_plain(reason)}", soft_wrap=True)
|
|
3937
4098
|
|
|
3938
4099
|
if failed and not delivered:
|
|
3939
4100
|
return 1
|
|
@@ -4133,7 +4294,9 @@ def _render_messages_table(messages, session_id: str, full_ids: bool = False) ->
|
|
|
4133
4294
|
table.add_column("From", style="cyan", no_wrap=full_ids)
|
|
4134
4295
|
table.add_column("Type", style="yellow", no_wrap=True)
|
|
4135
4296
|
table.add_column("R", justify="center", no_wrap=True)
|
|
4136
|
-
|
|
4297
|
+
# fold, not ellipsis: a path or SHA longer than the column wraps instead
|
|
4298
|
+
# of being cut (a non-TTY console is 80 columns wide).
|
|
4299
|
+
table.add_column("Message", overflow="fold")
|
|
4137
4300
|
|
|
4138
4301
|
for msg in messages:
|
|
4139
4302
|
ts = datetime.fromtimestamp(msg.timestamp).strftime("%m-%d %H:%M")
|
|
@@ -4149,6 +4312,88 @@ def _render_messages_table(messages, session_id: str, full_ids: bool = False) ->
|
|
|
4149
4312
|
console.print(table)
|
|
4150
4313
|
|
|
4151
4314
|
|
|
4315
|
+
def _runs_in_agent(registry) -> bool:
|
|
4316
|
+
"""Whether this command runs inside an agent session rather than for the person.
|
|
4317
|
+
|
|
4318
|
+
True when ``$QBRAID_SESSION_ID`` is set or the registry finds a calling
|
|
4319
|
+
session (ancestry), including one it cannot tell apart from another.
|
|
4320
|
+
Used for defaults that must fail safe for agents, never for permission.
|
|
4321
|
+
"""
|
|
4322
|
+
if os.environ.get("QBRAID_SESSION_ID"):
|
|
4323
|
+
return True
|
|
4324
|
+
find = _core_method(registry, "calling_session")
|
|
4325
|
+
if find is None:
|
|
4326
|
+
return False
|
|
4327
|
+
try:
|
|
4328
|
+
return bool(find())
|
|
4329
|
+
except Exception as err: # pylint: disable=broad-exception-caught
|
|
4330
|
+
return _is_registry_error(err)
|
|
4331
|
+
|
|
4332
|
+
|
|
4333
|
+
def _stdout_is_tty() -> bool:
|
|
4334
|
+
"""Whether stdout is a terminal (a person reading), not a pipe or an agent's shell."""
|
|
4335
|
+
import sys
|
|
4336
|
+
|
|
4337
|
+
try:
|
|
4338
|
+
return sys.stdout.isatty()
|
|
4339
|
+
except (AttributeError, ValueError):
|
|
4340
|
+
return False
|
|
4341
|
+
|
|
4342
|
+
|
|
4343
|
+
def _message_dict(msg) -> dict:
|
|
4344
|
+
"""An inbox message as a JSON-ready dict with its full text.
|
|
4345
|
+
|
|
4346
|
+
Uses Core's ``message_to_dict`` when present so the shape has one
|
|
4347
|
+
definition; older Core gets the same keys built here.
|
|
4348
|
+
"""
|
|
4349
|
+
# pylint: disable-next=import-outside-toplevel
|
|
4350
|
+
from qbraid_core.services.agents import messaging as core_messaging
|
|
4351
|
+
|
|
4352
|
+
to_dict = getattr(core_messaging, "message_to_dict", None)
|
|
4353
|
+
if callable(to_dict):
|
|
4354
|
+
return to_dict(msg) # pylint: disable=not-callable
|
|
4355
|
+
msg_type = getattr(msg.type, "value", msg.type)
|
|
4356
|
+
return {
|
|
4357
|
+
"id": msg.id,
|
|
4358
|
+
"from": msg.from_session,
|
|
4359
|
+
"to": msg.to_session,
|
|
4360
|
+
"type": msg_type,
|
|
4361
|
+
"timestamp": msg.timestamp,
|
|
4362
|
+
"read": msg.read,
|
|
4363
|
+
"text": msg.text,
|
|
4364
|
+
"forwarded_from": getattr(msg, "forwarded_from", None),
|
|
4365
|
+
"forwarded_to": getattr(msg, "forwarded_to", None),
|
|
4366
|
+
}
|
|
4367
|
+
|
|
4368
|
+
|
|
4369
|
+
def _echo_json(value) -> None:
|
|
4370
|
+
"""Print JSON as plain text: no Rich markup, wrapping or highlighting."""
|
|
4371
|
+
typer.echo(json.dumps(value, ensure_ascii=False))
|
|
4372
|
+
|
|
4373
|
+
|
|
4374
|
+
_MESSAGE_TYPES = ("message", "task_assignment", "status_update", "shutdown_request")
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
def _check_message_type(message_type: Optional[str]) -> None:
|
|
4378
|
+
if message_type is not None and message_type not in _MESSAGE_TYPES:
|
|
4379
|
+
console.print(
|
|
4380
|
+
f"[red]Error:[/red] Unknown --type {_plain(message_type)!r}. "
|
|
4381
|
+
f"Use one of: {', '.join(_MESSAGE_TYPES)}."
|
|
4382
|
+
)
|
|
4383
|
+
raise typer.Exit(code=2)
|
|
4384
|
+
|
|
4385
|
+
|
|
4386
|
+
def _filter_messages(messages, from_prefix, message_type, since_ts):
|
|
4387
|
+
"""Messages matching a sender-id prefix, a type and a start time."""
|
|
4388
|
+
return [
|
|
4389
|
+
m
|
|
4390
|
+
for m in messages
|
|
4391
|
+
if (not from_prefix or m.from_session.startswith(from_prefix))
|
|
4392
|
+
and (not message_type or getattr(m.type, "value", m.type) == message_type)
|
|
4393
|
+
and (since_ts is None or m.timestamp >= since_ts)
|
|
4394
|
+
]
|
|
4395
|
+
|
|
4396
|
+
|
|
4152
4397
|
# Cross-host messaging transport: qBraid-CLI#328 / qbraid-core#307.
|
|
4153
4398
|
@inbox_app.callback()
|
|
4154
4399
|
def inbox_default( # pylint: disable=too-many-arguments
|
|
@@ -4165,11 +4410,37 @@ def inbox_default( # pylint: disable=too-many-arguments
|
|
|
4165
4410
|
),
|
|
4166
4411
|
follow: bool = typer.Option(False, "--follow", "-f", help="Stream new messages as they arrive."),
|
|
4167
4412
|
unread: bool = typer.Option(False, "--unread", "-u", help="Show only unread messages."),
|
|
4168
|
-
limit: int = typer.Option(50, "--limit", "-n", help="Max messages to show (most recent)."),
|
|
4169
|
-
|
|
4170
|
-
|
|
4413
|
+
limit: int = typer.Option(50, "--limit", "-n", help="Max messages to show (most recent); 0 for all."),
|
|
4414
|
+
from_: Optional[str] = typer.Option(
|
|
4415
|
+
None, "--from", help="Only messages whose sender session id starts with this prefix."
|
|
4416
|
+
),
|
|
4417
|
+
message_type: Optional[str] = typer.Option(
|
|
4418
|
+
None,
|
|
4419
|
+
"--type",
|
|
4420
|
+
help="Only messages of this type: message, task_assignment, status_update, shutdown_request.",
|
|
4421
|
+
),
|
|
4422
|
+
since: Optional[str] = typer.Option(
|
|
4423
|
+
None, "--since", help="Only messages from the last period, e.g. 30m, 2h, 1d."
|
|
4424
|
+
),
|
|
4425
|
+
as_json: bool = typer.Option(
|
|
4426
|
+
False,
|
|
4427
|
+
"--json",
|
|
4428
|
+
help=(
|
|
4429
|
+
"Print a JSON array of the matching messages with full text and every field "
|
|
4430
|
+
"(id, from, to, type, timestamp, read, text, forwarded_from, forwarded_to). "
|
|
4431
|
+
"Does not mark anything read unless --mark-read is passed."
|
|
4432
|
+
),
|
|
4433
|
+
),
|
|
4434
|
+
mark_read_flag: Optional[bool] = typer.Option(
|
|
4435
|
+
None,
|
|
4171
4436
|
"--mark-read/--no-mark-read",
|
|
4172
|
-
help=
|
|
4437
|
+
help=(
|
|
4438
|
+
"Mark shown messages as read. Default: on only when a person (no agent "
|
|
4439
|
+
"session) prints the table to a terminal; off with --json, inside an agent "
|
|
4440
|
+
"session, or when stdout is not a terminal, so a message is never marked "
|
|
4441
|
+
"read unseen."
|
|
4442
|
+
),
|
|
4443
|
+
show_default=False,
|
|
4173
4444
|
),
|
|
4174
4445
|
wide: bool = typer.Option(
|
|
4175
4446
|
False,
|
|
@@ -4184,7 +4455,10 @@ def inbox_default( # pylint: disable=too-many-arguments
|
|
|
4184
4455
|
"""Read messages from an agent session's inbox.
|
|
4185
4456
|
|
|
4186
4457
|
Without a subcommand this reads the inbox (optionally streams with
|
|
4187
|
-
--follow).
|
|
4458
|
+
--follow). The table wraps long messages rather than cutting them; agents
|
|
4459
|
+
should use ``--json``, which never shortens text. Use ``qbraid agents
|
|
4460
|
+
inbox mark-read`` to mark manually, and ``qbraid agents wait`` to block
|
|
4461
|
+
until a new message arrives.
|
|
4188
4462
|
|
|
4189
4463
|
Same-host only: an inbox is a JSONL file under ``~/.qbraid/inboxes/`` on
|
|
4190
4464
|
the machine that owns it, so there is no ``--compute``. Cross-host
|
|
@@ -4200,15 +4474,41 @@ def inbox_default( # pylint: disable=too-many-arguments
|
|
|
4200
4474
|
handle_error(message=f"qbraid-core messaging unavailable: {err}", include_traceback=False)
|
|
4201
4475
|
raise typer.Exit(code=1) from err
|
|
4202
4476
|
|
|
4477
|
+
_check_message_type(message_type)
|
|
4478
|
+
if as_json and follow:
|
|
4479
|
+
console.print(
|
|
4480
|
+
"[red]Error:[/red] --json cannot be combined with --follow. "
|
|
4481
|
+
"Use 'qbraid agents wait --json' to block for the next message."
|
|
4482
|
+
)
|
|
4483
|
+
raise typer.Exit(code=2)
|
|
4484
|
+
since_ts = _since_to_timestamp(since) if since else None
|
|
4485
|
+
filtered = bool(from_ or message_type or since_ts is not None)
|
|
4486
|
+
|
|
4203
4487
|
# Registry-aware resolution so `--session <prefix>` and tmux names work
|
|
4204
|
-
#
|
|
4205
|
-
#
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4488
|
+
# (Persona A's #1 finding was that inbox silently returned "empty" for a
|
|
4489
|
+
# valid prefix), and the caller is found as send/send-to/whoami find it.
|
|
4490
|
+
registry = _get_registry()
|
|
4491
|
+
session_id = _resolve_session_id(session, registry=registry)
|
|
4492
|
+
# Explicit --mark-read/--no-mark-read wins. Otherwise mark only what a
|
|
4493
|
+
# person saw in the table on a terminal: never for an agent, whose shell
|
|
4494
|
+
# may well be a pty (Codex, tmux, script) yet reads nothing it is shown.
|
|
4495
|
+
agent_caller = _runs_in_agent(registry)
|
|
4496
|
+
if mark_read_flag is None:
|
|
4497
|
+
mark_read_flag = not as_json and not agent_caller and _stdout_is_tty()
|
|
4498
|
+
auto_skipped = not as_json and not mark_read_flag
|
|
4499
|
+
else:
|
|
4500
|
+
auto_skipped = False
|
|
4501
|
+
|
|
4502
|
+
def _read(limit_):
|
|
4503
|
+
if not filtered:
|
|
4504
|
+
return read_inbox(session_id, unread_only=unread, limit=limit_)
|
|
4505
|
+
matches = _filter_messages(
|
|
4506
|
+
read_inbox(session_id, unread_only=unread, limit=0), from_, message_type, since_ts
|
|
4507
|
+
)
|
|
4508
|
+
return matches[-limit_:] if limit_ > 0 else matches
|
|
4209
4509
|
|
|
4210
4510
|
if follow:
|
|
4211
|
-
existing =
|
|
4511
|
+
existing = _read(limit)
|
|
4212
4512
|
_render_messages_table(existing, session_id, full_ids=wide)
|
|
4213
4513
|
if mark_read_flag and existing:
|
|
4214
4514
|
mark_read(session_id, message_ids=[m.id for m in existing if not m.read])
|
|
@@ -4216,6 +4516,8 @@ def inbox_default( # pylint: disable=too-many-arguments
|
|
|
4216
4516
|
console.print("[dim]Watching for new messages… Ctrl-C to stop.[/dim]")
|
|
4217
4517
|
try:
|
|
4218
4518
|
for msg in watch_inbox(session_id):
|
|
4519
|
+
if not _filter_messages([msg], from_, message_type, since_ts):
|
|
4520
|
+
continue
|
|
4219
4521
|
ts = datetime.fromtimestamp(msg.timestamp).strftime("%H:%M:%S")
|
|
4220
4522
|
from_display = msg.from_session if wide else msg.from_session[:12]
|
|
4221
4523
|
console.print(
|
|
@@ -4229,15 +4531,23 @@ def inbox_default( # pylint: disable=too-many-arguments
|
|
|
4229
4531
|
console.print("[dim]Stopped watching.[/dim]")
|
|
4230
4532
|
return
|
|
4231
4533
|
|
|
4232
|
-
messages =
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4534
|
+
messages = _read(limit)
|
|
4535
|
+
if as_json:
|
|
4536
|
+
_echo_json([_message_dict(m) for m in messages])
|
|
4537
|
+
else:
|
|
4538
|
+
_render_messages_table(messages, session_id, full_ids=wide)
|
|
4539
|
+
|
|
4540
|
+
unread_ids = [m.id for m in messages if not m.read and not getattr(m, "forwarded_to", None)]
|
|
4541
|
+
if mark_read_flag and unread_ids:
|
|
4542
|
+
n = mark_read(session_id, message_ids=unread_ids)
|
|
4543
|
+
if n and not as_json:
|
|
4544
|
+
console.print(f"[dim]Marked {n} message(s) as read.[/dim]")
|
|
4545
|
+
elif auto_skipped and unread_ids:
|
|
4546
|
+
console.print(
|
|
4547
|
+
f"[dim]{len(unread_ids)} unread message(s) left unread "
|
|
4548
|
+
f"({'agent session' if agent_caller else 'stdout is not a terminal'}). "
|
|
4549
|
+
"Pass --mark-read to mark them, or use --json for full text.[/dim]"
|
|
4550
|
+
)
|
|
4241
4551
|
|
|
4242
4552
|
|
|
4243
4553
|
@inbox_app.command("mark-read")
|
|
@@ -4272,13 +4582,195 @@ def inbox_mark_read(
|
|
|
4272
4582
|
handle_error(message=f"qbraid-core messaging unavailable: {err}", include_traceback=False)
|
|
4273
4583
|
raise typer.Exit(code=1) from err
|
|
4274
4584
|
|
|
4275
|
-
session_id = _resolve_session_id(session
|
|
4585
|
+
session_id = _resolve_session_id(session)
|
|
4276
4586
|
ids = list(message_id) if message_id else None
|
|
4277
4587
|
|
|
4278
4588
|
n = mark_read(session_id, message_ids=ids)
|
|
4279
4589
|
console.print(f"[green]Marked {n} message(s) as read[/green] for {session_id[:12]}.")
|
|
4280
4590
|
|
|
4281
4591
|
|
|
4592
|
+
# =============================================================================
|
|
4593
|
+
# `qbraid agents wait` / `qbraid agents whoami`
|
|
4594
|
+
# =============================================================================
|
|
4595
|
+
|
|
4596
|
+
#: ``qbraid agents wait`` exit code when the timeout passes with no matching
|
|
4597
|
+
#: message. Same as timeout(1); 2 is Click's usage-error code.
|
|
4598
|
+
WAIT_TIMEOUT_EXIT_CODE = 124
|
|
4599
|
+
|
|
4600
|
+
|
|
4601
|
+
def _core_messaging_function(name: str, purpose: str):
|
|
4602
|
+
"""A qbraid-core messaging function, or exit 1 saying Core must be upgraded."""
|
|
4603
|
+
try:
|
|
4604
|
+
# pylint: disable-next=import-outside-toplevel
|
|
4605
|
+
from qbraid_core.services.agents import messaging as core_messaging
|
|
4606
|
+
except ImportError as err:
|
|
4607
|
+
handle_error(message=f"qbraid-core messaging unavailable: {err}", include_traceback=False)
|
|
4608
|
+
raise typer.Exit(code=1) from err
|
|
4609
|
+
function = getattr(core_messaging, name, None)
|
|
4610
|
+
if not callable(function):
|
|
4611
|
+
console.print(
|
|
4612
|
+
f"[red]{purpose} needs a newer qbraid-core[/red] (one that provides "
|
|
4613
|
+
f"messaging.{name}). Upgrade with: pip install -U qbraid-core"
|
|
4614
|
+
)
|
|
4615
|
+
raise typer.Exit(code=1)
|
|
4616
|
+
return function
|
|
4617
|
+
|
|
4618
|
+
|
|
4619
|
+
# Cross-host messaging transport: qBraid-CLI#328 / qbraid-core#307.
|
|
4620
|
+
@agents_app.command("wait")
|
|
4621
|
+
def agents_wait( # pylint: disable=too-many-arguments
|
|
4622
|
+
from_: Optional[str] = typer.Option(
|
|
4623
|
+
None, "--from", help="Only a message whose sender session id starts with this prefix."
|
|
4624
|
+
),
|
|
4625
|
+
message_type: Optional[str] = typer.Option(
|
|
4626
|
+
None,
|
|
4627
|
+
"--type",
|
|
4628
|
+
help="Only a message of this type: message, task_assignment, status_update, shutdown_request.",
|
|
4629
|
+
),
|
|
4630
|
+
timeout: float = typer.Option(
|
|
4631
|
+
600.0, "--timeout", "-t", min=0, help="Seconds to wait before giving up; 0 checks once."
|
|
4632
|
+
),
|
|
4633
|
+
as_json: bool = typer.Option(
|
|
4634
|
+
False,
|
|
4635
|
+
"--json",
|
|
4636
|
+
help="Print the message as one JSON object (same fields as 'inbox --json'); 'null' on timeout.",
|
|
4637
|
+
),
|
|
4638
|
+
mark_read_flag: bool = typer.Option(
|
|
4639
|
+
False,
|
|
4640
|
+
"--mark-read",
|
|
4641
|
+
help=(
|
|
4642
|
+
"Claim the message: return it only if this call marked it read, so two "
|
|
4643
|
+
"waiters never both get it. At-most-once; for at-least-once, mark it read "
|
|
4644
|
+
"after handling it. Off by default."
|
|
4645
|
+
),
|
|
4646
|
+
),
|
|
4647
|
+
include_unread: bool = typer.Option(
|
|
4648
|
+
False,
|
|
4649
|
+
"--include-unread",
|
|
4650
|
+
help="Return a matching message that is already unread at once, instead of only new ones.",
|
|
4651
|
+
),
|
|
4652
|
+
session: Optional[str] = typer.Option(
|
|
4653
|
+
None,
|
|
4654
|
+
"--session",
|
|
4655
|
+
"-s",
|
|
4656
|
+
help="Session whose inbox to wait on (id, prefix or name). Defaults to $QBRAID_SESSION_ID.",
|
|
4657
|
+
),
|
|
4658
|
+
) -> None:
|
|
4659
|
+
"""Block until a new inbox message arrives.
|
|
4660
|
+
|
|
4661
|
+
Returns the first message that arrives after the command starts and
|
|
4662
|
+
matches --from and --type, then exits. Use it instead of a polling loop.
|
|
4663
|
+
|
|
4664
|
+
Exit codes: 0 a message arrived (printed; JSON with --json), 124 the
|
|
4665
|
+
timeout passed with no match, 1 an error, 2 a usage error, 130
|
|
4666
|
+
interrupted.
|
|
4667
|
+
|
|
4668
|
+
Same-host only: an inbox is a JSONL file under ``~/.qbraid/inboxes/`` on
|
|
4669
|
+
the machine that owns it.
|
|
4670
|
+
"""
|
|
4671
|
+
if not math.isfinite(timeout):
|
|
4672
|
+
# FloatRange(min=0) lets nan and inf through; neither is a timeout.
|
|
4673
|
+
console.print("[red]Error:[/red] --timeout must be a finite number of seconds.")
|
|
4674
|
+
raise typer.Exit(code=2)
|
|
4675
|
+
wait_for_message = _core_messaging_function("wait_for_message", "qbraid agents wait")
|
|
4676
|
+
_check_message_type(message_type)
|
|
4677
|
+
session_id = _resolve_session_id(session)
|
|
4678
|
+
try:
|
|
4679
|
+
message = wait_for_message( # pylint: disable=not-callable
|
|
4680
|
+
session_id,
|
|
4681
|
+
timeout=timeout,
|
|
4682
|
+
from_prefix=from_ or None,
|
|
4683
|
+
message_type=message_type,
|
|
4684
|
+
mark_read=mark_read_flag,
|
|
4685
|
+
include_unread=include_unread,
|
|
4686
|
+
)
|
|
4687
|
+
except KeyboardInterrupt as err:
|
|
4688
|
+
raise typer.Exit(code=130) from err
|
|
4689
|
+
except ValueError as err:
|
|
4690
|
+
console.print(f"[red]Error:[/red] {_plain(err)}")
|
|
4691
|
+
raise typer.Exit(code=2) from err
|
|
4692
|
+
|
|
4693
|
+
if message is None:
|
|
4694
|
+
if as_json:
|
|
4695
|
+
_echo_json(None)
|
|
4696
|
+
Console(stderr=True).print(f"[yellow]No matching message within {timeout:g}s.[/yellow]")
|
|
4697
|
+
raise typer.Exit(code=WAIT_TIMEOUT_EXIT_CODE)
|
|
4698
|
+
if as_json:
|
|
4699
|
+
_echo_json(message)
|
|
4700
|
+
return
|
|
4701
|
+
when = datetime.fromtimestamp(message["timestamp"]).strftime("%Y-%m-%d %H:%M:%S")
|
|
4702
|
+
typer.echo(f"From {message['from']} ({message['type']}, id={message['id']}) at {when}:")
|
|
4703
|
+
typer.echo(message["text"])
|
|
4704
|
+
|
|
4705
|
+
|
|
4706
|
+
@agents_app.command("whoami")
|
|
4707
|
+
def agents_whoami(
|
|
4708
|
+
as_json: bool = typer.Option(False, "--json", help="Print the identity as one JSON object."),
|
|
4709
|
+
session: Optional[str] = typer.Option(
|
|
4710
|
+
None, "--session", "-s", help="Describe this session (id, prefix or name) instead of the caller."
|
|
4711
|
+
),
|
|
4712
|
+
) -> None:
|
|
4713
|
+
"""Show this agent's identity and contacts.
|
|
4714
|
+
|
|
4715
|
+
Reports the session id (from process ancestry or $QBRAID_SESSION_ID),
|
|
4716
|
+
name, agent type, team, parent, tool, inbox path, the registry's
|
|
4717
|
+
canonical id and resume link, the messaging rule, and the running
|
|
4718
|
+
sessions it may message. The session is found the way send and send-to
|
|
4719
|
+
find it; "source" says how (ancestry or env). Exits 1 outside an agent
|
|
4720
|
+
session (the caller is the person) and when the caller fits more than one
|
|
4721
|
+
live session; --json still prints the object, with "session_id": null and,
|
|
4722
|
+
for the ambiguous case, an "error" field.
|
|
4723
|
+
"""
|
|
4724
|
+
whoami = _core_messaging_function("whoami", "qbraid agents whoami")
|
|
4725
|
+
registry = _get_registry()
|
|
4726
|
+
explicit = _resolve_session_id(session, registry=registry) if session else None
|
|
4727
|
+
info = whoami(session_id=explicit, registry=registry) # pylint: disable=not-callable
|
|
4728
|
+
if as_json:
|
|
4729
|
+
_echo_json(info)
|
|
4730
|
+
elif info.get("error"):
|
|
4731
|
+
console.print(f"[red]Cannot tell which agent session this is: {_plain(info['error'])}[/red]")
|
|
4732
|
+
elif not info.get("session_id"):
|
|
4733
|
+
console.print(
|
|
4734
|
+
"Not inside a qBraid agent session: commands here act as the person. "
|
|
4735
|
+
"Agent shells set QBRAID_SESSION_ID."
|
|
4736
|
+
)
|
|
4737
|
+
else:
|
|
4738
|
+
rows = [
|
|
4739
|
+
("Session", info["session_id"]),
|
|
4740
|
+
("Source", info.get("source")),
|
|
4741
|
+
("Name", info.get("name")),
|
|
4742
|
+
("Type", info.get("type")),
|
|
4743
|
+
("Team", info.get("team")),
|
|
4744
|
+
("Parent", info.get("parent")),
|
|
4745
|
+
("Children", ", ".join(info.get("children") or [])),
|
|
4746
|
+
("Tool", info.get("tool")),
|
|
4747
|
+
("Status", info.get("status")),
|
|
4748
|
+
("Inbox", info.get("inbox_path")),
|
|
4749
|
+
("Canonical id", info.get("canonical_session_id")),
|
|
4750
|
+
("Resumed from", info.get("resumed_from")),
|
|
4751
|
+
("Rule", info.get("message_rule")),
|
|
4752
|
+
]
|
|
4753
|
+
if not info.get("registered"):
|
|
4754
|
+
rows.append(("Registered", "no (not in this host's registry)"))
|
|
4755
|
+
for label, value in rows:
|
|
4756
|
+
if value:
|
|
4757
|
+
console.print(f"[bold]{label}:[/bold] {_plain(value)}", soft_wrap=True)
|
|
4758
|
+
recipients = info.get("allowed_recipients") or []
|
|
4759
|
+
if recipients:
|
|
4760
|
+
console.print("[bold]May message:[/bold]")
|
|
4761
|
+
for row in recipients:
|
|
4762
|
+
name = f" '{row['name']}'" if row.get("name") else ""
|
|
4763
|
+
team = f", team {row['team']}" if row.get("team") else ""
|
|
4764
|
+
console.print(
|
|
4765
|
+
f" {_plain(row['session_id'])} ({_plain(row['type'])}{_plain(name)}{_plain(team)})",
|
|
4766
|
+
soft_wrap=True,
|
|
4767
|
+
)
|
|
4768
|
+
elif info.get("registered"):
|
|
4769
|
+
console.print("[bold]May message:[/bold] no running session")
|
|
4770
|
+
if not info.get("session_id"):
|
|
4771
|
+
raise typer.Exit(code=1)
|
|
4772
|
+
|
|
4773
|
+
|
|
4282
4774
|
# =============================================================================
|
|
4283
4775
|
# `qbraid agents team <id>` — leader-centric roster view
|
|
4284
4776
|
# =============================================================================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qbraid-cli
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.18
|
|
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.0
|
|
32
32
|
Requires-Dist: questionary>=2.0.0
|
|
33
|
-
Requires-Dist: qbraid-core>=0.6.
|
|
33
|
+
Requires-Dist: qbraid-core>=0.6.45
|
|
34
34
|
Provides-Extra: compute
|
|
35
|
-
Requires-Dist: qbraid-core[compute]>=0.6.
|
|
35
|
+
Requires-Dist: qbraid-core[compute]>=0.6.45; extra == "compute"
|
|
36
36
|
Provides-Extra: envs
|
|
37
|
-
Requires-Dist: qbraid-core[environments]>=0.6.
|
|
37
|
+
Requires-Dist: qbraid-core[environments]>=0.6.45; 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.0
|
|
4
4
|
questionary>=2.0.0
|
|
5
|
-
qbraid-core>=0.6.
|
|
5
|
+
qbraid-core>=0.6.45
|
|
6
6
|
|
|
7
7
|
[compute]
|
|
8
|
-
qbraid-core[compute]>=0.6.
|
|
8
|
+
qbraid-core[compute]>=0.6.45
|
|
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.45
|
|
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
|