qbraid-cli 0.17.0__tar.gz → 0.17.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {qbraid_cli-0.17.0/qbraid_cli.egg-info → qbraid_cli-0.17.1}/PKG-INFO +4 -4
  2. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/pyproject.toml +4 -4
  3. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/app.py +339 -7
  4. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1/qbraid_cli.egg-info}/PKG-INFO +4 -4
  5. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli.egg-info/requires.txt +3 -3
  6. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/LICENSE +0 -0
  7. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/README.md +0 -0
  8. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/__init__.py +0 -0
  9. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/_build_info.py +0 -0
  10. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/_version.py +0 -0
  11. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/account/__init__.py +0 -0
  12. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/account/app.py +0 -0
  13. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/admin/__init__.py +0 -0
  14. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/admin/app.py +0 -0
  15. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/admin/headers.py +0 -0
  16. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/admin/validation.py +0 -0
  17. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/__init__.py +0 -0
  18. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/keep_alive.py +0 -0
  19. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/permission_response.py +0 -0
  20. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/provider_children.py +0 -0
  21. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/queue.py +0 -0
  22. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/agents/work.py +0 -0
  23. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/ai/__init__.py +0 -0
  24. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/ai/app.py +0 -0
  25. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/ai/token.py +0 -0
  26. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/artifacts/__init__.py +0 -0
  27. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/artifacts/app.py +0 -0
  28. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/comms/__init__.py +0 -0
  29. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/comms/app.py +0 -0
  30. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/__init__.py +0 -0
  31. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/app.py +0 -0
  32. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/instances.py +0 -0
  33. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/profiles.py +0 -0
  34. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/server.py +0 -0
  35. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/compute/ssh.py +0 -0
  36. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/configure/__init__.py +0 -0
  37. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/configure/actions.py +0 -0
  38. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/configure/app.py +0 -0
  39. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/devices/__init__.py +0 -0
  40. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/devices/app.py +0 -0
  41. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/devices/validation.py +0 -0
  42. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/__init__.py +0 -0
  43. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/activate.py +0 -0
  44. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/app.py +0 -0
  45. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/create.py +0 -0
  46. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/data_handling.py +0 -0
  47. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/groups.py +0 -0
  48. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/publish.py +0 -0
  49. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/registry.py +0 -0
  50. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/envs/share.py +0 -0
  51. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/exceptions.py +0 -0
  52. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/handlers.py +0 -0
  53. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/jobs/__init__.py +0 -0
  54. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/jobs/app.py +0 -0
  55. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/jobs/groups.py +0 -0
  56. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/kernels/__init__.py +0 -0
  57. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/kernels/app.py +0 -0
  58. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/lab/__init__.py +0 -0
  59. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/lab/app.py +0 -0
  60. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/main.py +0 -0
  61. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/pip/__init__.py +0 -0
  62. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/pip/app.py +0 -0
  63. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/pip/hooks.py +0 -0
  64. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/projects/__init__.py +0 -0
  65. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/projects/app.py +0 -0
  66. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/py.typed +0 -0
  67. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/skills/__init__.py +0 -0
  68. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/skills/app.py +0 -0
  69. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/troubleshoot/__init__.py +0 -0
  70. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli/troubleshoot/app.py +0 -0
  71. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli.egg-info/SOURCES.txt +0 -0
  72. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli.egg-info/dependency_links.txt +0 -0
  73. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli.egg-info/entry_points.txt +0 -0
  74. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/qbraid_cli.egg-info/top_level.txt +0 -0
  75. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/setup.cfg +0 -0
  76. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/tests/test_cli_e2e.py +0 -0
  77. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/tests/test_register_client.py +0 -0
  78. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/tests/test_status_colors.py +0 -0
  79. {qbraid_cli-0.17.0 → qbraid_cli-0.17.1}/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.0
3
+ Version: 0.17.1
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.54
33
+ Requires-Dist: qbraid-core>=0.6.55
34
34
  Provides-Extra: compute
35
- Requires-Dist: qbraid-core[compute]>=0.6.54; extra == "compute"
35
+ Requires-Dist: qbraid-core[compute]>=0.6.55; extra == "compute"
36
36
  Provides-Extra: envs
37
- Requires-Dist: qbraid-core[environments]>=0.6.54; extra == "envs"
37
+ Requires-Dist: qbraid-core[environments]>=0.6.55; 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.0"
7
+ version = "0.17.1"
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.54",
35
+ "qbraid-core>=0.6.55",
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.54"]
47
- envs = ["qbraid-core[environments]>=0.6.54"]
46
+ compute = ["qbraid-core[compute]>=0.6.55"]
47
+ envs = ["qbraid-core[environments]>=0.6.55"]
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,96 @@ 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
+
2062
2235
  @agents_app.command("settings")
2063
2236
  def agents_settings(
2064
2237
  execution_mode: Optional[ExecutionMode] = typer.Option(
2065
2238
  None, "--execution-mode", help="Save the Codex execution default for this machine."
2066
2239
  ),
2067
2240
  reset: bool = typer.Option(False, "--reset", help="Remove this machine's execution preference."),
2241
+ messaging: Optional[MessagingMode] = typer.Option(
2242
+ None,
2243
+ "--messaging",
2244
+ help=(
2245
+ "open (the default): any of your agents may message any other, on any of your machines. "
2246
+ "restricted: the role rules (workers reach their parent, children and team leaders); "
2247
+ "for agents that read untrusted input. Anyone may restrict; only a person may open."
2248
+ ),
2249
+ ),
2068
2250
  json_output: bool = typer.Option(
2069
2251
  False, "--json", help="Print structured settings and sandbox readiness."
2070
2252
  ),
2071
2253
  ):
2072
- """Inspect or configure agent execution.
2254
+ """Configure agent execution and messaging.
2073
2255
 
2074
- Defaults are shared by the CLI and dashboard on this machine.
2256
+ Inspect or change them. Defaults are shared by the CLI and dashboard on this machine.
2075
2257
  """
2258
+ if messaging is not None:
2259
+ if reset or execution_mode is not None:
2260
+ console.print(
2261
+ "[red]Error:[/red] Set --messaging on its own (not with --reset or --execution-mode)."
2262
+ )
2263
+ raise typer.Exit(code=2)
2264
+ _messaging_setting(messaging.value, json_output)
2265
+ return
2076
2266
  try:
2077
2267
  from qbraid_core.services.agents.execution import execution_settings, set_execution_default
2078
2268
 
@@ -2084,9 +2274,12 @@ def agents_settings(
2084
2274
  settings = set_execution_default(execution_mode.value)
2085
2275
  else:
2086
2276
  settings = execution_settings()
2277
+ current_messaging = _current_messaging()
2087
2278
  if json_output:
2088
- print(json.dumps(settings))
2279
+ print(json.dumps({**settings, **({"messaging": current_messaging} if current_messaging else {})}))
2089
2280
  else:
2281
+ if current_messaging:
2282
+ console.print(f"Messaging: {current_messaging} (this machine).")
2090
2283
  console.print(
2091
2284
  "Codex execution default: " + (settings["execution_mode"] or "not set (legacy defaults)")
2092
2285
  )
@@ -2488,6 +2681,15 @@ def agents_launch(
2488
2681
  "decides. yolo: no permission checks. ask/auto: legacy modes, unchanged."
2489
2682
  ),
2490
2683
  ),
2684
+ messaging: Optional[MessagingMode] = typer.Option(
2685
+ None,
2686
+ "--messaging",
2687
+ help=(
2688
+ "This agent's messaging: open (it may message any of your agents) or restricted "
2689
+ "(the role rules). Default: the machine's (qbraid agents settings --messaging). "
2690
+ "Anyone may restrict; opening takes a person or a bypass-mode agent."
2691
+ ),
2692
+ ),
2491
2693
  trust_hooks: bool = typer.Option(
2492
2694
  False,
2493
2695
  "--trust-hooks",
@@ -2588,6 +2790,7 @@ def agents_launch(
2588
2790
  raise AgentLauncherError("Remote launches select the backend on the destination; omit --backend.")
2589
2791
  launcher = _backend_launcher(backend)
2590
2792
 
2793
+ messaging_value = messaging.value if messaging is not None else None
2591
2794
  # Remote launch via SSH
2592
2795
  if compute:
2593
2796
  links = _remote_link_kwargs(launcher.remote_launch, team, parent, repo, detached=detached)
@@ -2605,6 +2808,7 @@ def agents_launch(
2605
2808
  **_approval_kwargs(launcher.remote_launch, approval.value if approval else None),
2606
2809
  **_hook_trust_kwargs(launcher.remote_launch, True if trust_hooks else None),
2607
2810
  **_execution_kwargs(launcher.remote_launch, execution_mode.value if execution_mode else None),
2811
+ **_messaging_kwargs(launcher.remote_launch, messaging_value),
2608
2812
  )
2609
2813
  if links.get("parent_is_default") and not session.parent_session_id:
2610
2814
  console.print(
@@ -2631,6 +2835,7 @@ def agents_launch(
2631
2835
  **_hook_trust_kwargs(launcher.launch, True if trust_hooks else None),
2632
2836
  **_prompt_answer_kwargs(launcher.launch, trust_folder, skip_bypass_confirmation),
2633
2837
  **_execution_kwargs(launcher.launch, execution_mode.value if execution_mode else None),
2838
+ **_messaging_kwargs(launcher.launch, messaging_value),
2634
2839
  progress_callback=_clone_progress if repo else None,
2635
2840
  )
2636
2841
 
@@ -2678,6 +2883,10 @@ def agents_launch(
2678
2883
  except (typer.Exit, SystemExit):
2679
2884
  raise
2680
2885
  except Exception as e:
2886
+ if _is_messaging_mode_error(e):
2887
+ # e.g. an agent asking to launch an open child: one line, no traceback.
2888
+ console.print(f"[red]Not launched:[/red] {_plain(str(e))}", soft_wrap=True)
2889
+ raise typer.Exit(code=1) from None
2681
2890
  handle_error(message=str(e))
2682
2891
  raise typer.Exit(code=1)
2683
2892
 
@@ -4671,6 +4880,23 @@ def _parse_target_csv(csv: str, registry) -> list[str]:
4671
4880
  return resolved
4672
4881
 
4673
4882
 
4883
+ def _waits_for_next_turn(registry, msg) -> Optional[str]:
4884
+ """``"SENDER_CANNOT_WAKE"`` when Core marked *msg* as not waking and its
4885
+ recipient holds such mail for its next turn (``messaging_mode.holds_for``)."""
4886
+ if getattr(msg, "wakes", None) is not False:
4887
+ return None
4888
+ try:
4889
+ # pylint: disable-next=import-outside-toplevel
4890
+ from qbraid_core.services.agents.messaging_mode import holds_for # type: ignore[attr-defined]
4891
+ except ImportError:
4892
+ return None
4893
+ try:
4894
+ recipient = registry.get_session(msg.to_session) if registry is not None else None
4895
+ except Exception: # pylint: disable=broad-exception-caught
4896
+ recipient = None # as Core decides: an unknown recipient holds it
4897
+ return "SENDER_CANNOT_WAKE" if recipient is None or holds_for(recipient) else None
4898
+
4899
+
4674
4900
  def _deliver_to_many(
4675
4901
  targets: list[str],
4676
4902
  text: str,
@@ -4699,6 +4925,7 @@ def _deliver_to_many(
4699
4925
  delivered: list[tuple[str, str]] = []
4700
4926
  failed: list[tuple[str, str]] = []
4701
4927
  forwards: dict = {}
4928
+ waits: dict = {}
4702
4929
  for target_sid in targets:
4703
4930
  try:
4704
4931
  msg = send_message(
@@ -4714,6 +4941,7 @@ def _deliver_to_many(
4714
4941
  # Older Core has no forwarded_from; newer Core types it Optional[str].
4715
4942
  forwarded = getattr(msg, "forwarded_from", None)
4716
4943
  forwards[msg.id] = forwarded if isinstance(forwarded, str) else None
4944
+ waits[msg.id] = _waits_for_next_turn(registry, msg)
4717
4945
  if isinstance(forwarded, str) and forwarded and not as_json:
4718
4946
  old_sid, new_sid = str(forwarded), str(msg.to_session)
4719
4947
  console.print(
@@ -4729,7 +4957,13 @@ def _deliver_to_many(
4729
4957
  _echo_json(
4730
4958
  {
4731
4959
  "delivered": [
4732
- {"to": sid, "id": mid, "type": message_type, "forwarded_from": forwards.get(mid)}
4960
+ {
4961
+ "to": sid,
4962
+ "id": mid,
4963
+ "type": message_type,
4964
+ "forwarded_from": forwards.get(mid),
4965
+ **({"held": waits[mid]} if waits.get(mid) else {}),
4966
+ }
4733
4967
  for sid, mid in delivered
4734
4968
  ],
4735
4969
  "failed": [{"to": sid, "error": reason} for sid, reason in failed],
@@ -4743,6 +4977,11 @@ def _deliver_to_many(
4743
4977
  f"[green]→[/green] Sent to [bold]{_plain(sid)}[/bold] "
4744
4978
  f"[dim](id={_plain(mid)}, type={_plain(message_type)})[/dim]"
4745
4979
  )
4980
+ if waits.get(mid):
4981
+ console.print(
4982
+ f"[dim]It waits for {_plain(sid[:8])}'s next turn ({waits[mid]}): only the person, "
4983
+ "or an agent they launched in a bypass mode, can wake it.[/dim]"
4984
+ )
4746
4985
  for sid, reason in failed_shown:
4747
4986
  # soft_wrap: a refusal stays one line, so grep-based checks still match.
4748
4987
  console.print(f"[red]✗[/red] [bold]{_plain(sid)}[/bold]: {_plain(reason)}", soft_wrap=True)
@@ -4952,6 +5191,8 @@ def _send_to( # pylint: disable=too-many-arguments
4952
5191
  reply_alias: Optional[str],
4953
5192
  request_id: Optional[str],
4954
5193
  as_json: bool = False,
5194
+ ask: bool = False,
5195
+ reason: str = "",
4955
5196
  ) -> None:
4956
5197
  try:
4957
5198
  # pylint: disable-next=import-outside-toplevel,unused-import
@@ -5019,6 +5260,8 @@ def _send_to( # pylint: disable=too-many-arguments
5019
5260
  # the resume itself, so the message records where it was addressed
5020
5261
  # (forwarded_from) and the "resumed as" note is printed.
5021
5262
  to_sid = to
5263
+ if ask and _ask_person(registry, from_sid, to_sid, text, reason, as_json, message_type):
5264
+ return
5022
5265
  code = _deliver_to_many(
5023
5266
  [to_sid],
5024
5267
  text,
@@ -5033,6 +5276,58 @@ def _send_to( # pylint: disable=too-many-arguments
5033
5276
  raise typer.Exit(code=code)
5034
5277
 
5035
5278
 
5279
+ def _ask_person( # pylint: disable=too-many-arguments
5280
+ registry, from_sid: str, to_sid: str, text: str, reason: str, as_json: bool, message_type: str = "message"
5281
+ ) -> bool:
5282
+ """With ``--ask``: hold the message for a person when the rules refuse it.
5283
+
5284
+ Returns False when the sender may message the target anyway (then it is
5285
+ delivered as usual). Exits 5 once a request is filed, 1 when it cannot be.
5286
+ """
5287
+ try:
5288
+ # pylint: disable-next=import-outside-toplevel
5289
+ # qbraid-core with message requests (qbraid-core#593); older ones raise ImportError below.
5290
+ from qbraid_core.services.agents.messaging import ( # type: ignore[attr-defined]
5291
+ request_person_approval,
5292
+ )
5293
+ except ImportError:
5294
+ console.print(
5295
+ "[red]--ask needs a newer qbraid-core[/red] (one with message requests). "
5296
+ "Upgrade with: pip install -U qbraid-core"
5297
+ )
5298
+ raise typer.Exit(code=1) from None
5299
+ if from_sid == "person":
5300
+ return False # A person asks no one: the rules for a person apply as usual.
5301
+ try:
5302
+ row = request_person_approval(
5303
+ registry, from_sid, to_sid, text, reason=reason, message_type=message_type
5304
+ )
5305
+ except Exception as err: # pylint: disable=broad-exception-caught
5306
+ if as_json:
5307
+ print(
5308
+ json.dumps(
5309
+ {"error": {"code": getattr(err, "code", "MESSAGE_REQUEST_FAILED"), "message": str(err)}}
5310
+ )
5311
+ )
5312
+ else:
5313
+ console.print(f"[red]Not sent:[/red] {_plain(str(err))}")
5314
+ raise typer.Exit(code=1) from None
5315
+ if row.get("state") == "not_needed":
5316
+ return False
5317
+ if as_json:
5318
+ print(
5319
+ json.dumps(
5320
+ {"requested": {key: row.get(key) for key in ("id", "state", "to_session_id", "created_at")}}
5321
+ )
5322
+ )
5323
+ else:
5324
+ console.print(
5325
+ f"Held for a person to approve (request {row.get('id')}): the Lab's Agents sidebar lists it "
5326
+ "under Message requests. Nothing is delivered until they allow it."
5327
+ )
5328
+ raise typer.Exit(code=5)
5329
+
5330
+
5036
5331
  def _bad_alias(alias: str) -> bool:
5037
5332
  """An alias ssh could read as an option, or that is not one word."""
5038
5333
  return not alias or alias.startswith("-") or any(char.isspace() for char in alias)
@@ -5118,6 +5413,21 @@ def agents_send_to( # pylint: disable=too-many-arguments
5118
5413
  'or {"error": {code, message, request_id}}. Same exit codes.'
5119
5414
  ),
5120
5415
  ),
5416
+ ask: bool = typer.Option(
5417
+ False,
5418
+ "--ask",
5419
+ help=(
5420
+ "If the messaging rules do not let you message this agent, hold the exact text "
5421
+ "for a person to approve (Agents sidebar, Message requests) instead of failing. "
5422
+ "Exit 5 while it waits; the sender's inbox is told the outcome. With --json: "
5423
+ '{"requested": {id, state, to_session_id, created_at}}.'
5424
+ ),
5425
+ ),
5426
+ reason: str = typer.Option(
5427
+ "",
5428
+ "--reason",
5429
+ help="With --ask: one line telling the person why (e.g. 'the person asked us to sync').",
5430
+ ),
5121
5431
  ) -> None:
5122
5432
  """Send a message to another agent's inbox.
5123
5433
 
@@ -5134,10 +5444,29 @@ def agents_send_to( # pylint: disable=too-many-arguments
5134
5444
  (leader/worker/observer/reviewer) apply on both machines; an answer to a
5135
5445
  message the other agent sent you is always allowed.
5136
5446
 
5447
+ ``--ask``: when the rules refuse, the text is held for a person to allow
5448
+ once, allow for a while, or deny, in the Lab's Agents sidebar. Nothing is
5449
+ delivered until then; an agent cannot approve its own request.
5450
+
5137
5451
  Exit codes: 0 delivered, 1 not delivered, 2 usage error, 3 partial
5138
5452
  (broadcast), 4 a cross-machine send whose outcome is unknown: retry with
5139
- the printed ``--request-id``.
5453
+ the printed ``--request-id``, 5 held for a person's approval (``--ask``).
5140
5454
  """
5455
+ if ask and (compute or reply):
5456
+ console.print(
5457
+ "[red]Error:[/red] --ask is for agents on this machine; "
5458
+ "it does not combine with --compute or --reply."
5459
+ )
5460
+ raise typer.Exit(code=2)
5461
+ if reason and not ask:
5462
+ console.print("[red]Error:[/red] --reason goes with --ask.")
5463
+ raise typer.Exit(code=2)
5464
+ if ask and no_permission_check:
5465
+ console.print(
5466
+ "[red]Error:[/red] --ask asks a person to let a refused message through; "
5467
+ "it does not combine with --no-permission-check."
5468
+ )
5469
+ raise typer.Exit(code=2)
5141
5470
  if reply and text is not None:
5142
5471
  console.print("[red]Error:[/red] --reply goes to the message's sender; do not also name a target.")
5143
5472
  raise typer.Exit(code=2)
@@ -5157,6 +5486,8 @@ def agents_send_to( # pylint: disable=too-many-arguments
5157
5486
  reply_alias=reply_alias,
5158
5487
  request_id=request_id,
5159
5488
  as_json=as_json,
5489
+ ask=ask,
5490
+ reason=reason,
5160
5491
  )
5161
5492
 
5162
5493
 
@@ -5821,9 +6152,9 @@ def agents_nudge_clear(
5821
6152
  target = _resolve_session_id(session_id, registry=registry)
5822
6153
  else:
5823
6154
  whoami = _core_messaging_function("whoami", "qbraid agents nudge-clear")
5824
- target = (whoami(session_id=None, registry=registry) or {}).get( # pylint: disable=not-callable
6155
+ target = (whoami(session_id=None, registry=registry) or {}).get(
5825
6156
  "session_id"
5826
- )
6157
+ ) # pylint: disable=not-callable
5827
6158
  if not target:
5828
6159
  console.print("[red]Not inside an agent session: name the session to clear.[/red]")
5829
6160
  raise typer.Exit(code=2)
@@ -5894,6 +6225,7 @@ def agents_whoami(
5894
6225
  ),
5895
6226
  ),
5896
6227
  ("Rule", info.get("message_rule")),
6228
+ ("Messaging", info.get("messaging_note") or info.get("messaging")),
5897
6229
  ]
5898
6230
  if not info.get("registered"):
5899
6231
  rows.append(("Registered", "no (not in this host's registry)"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qbraid-cli
3
- Version: 0.17.0
3
+ Version: 0.17.1
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.54
33
+ Requires-Dist: qbraid-core>=0.6.55
34
34
  Provides-Extra: compute
35
- Requires-Dist: qbraid-core[compute]>=0.6.54; extra == "compute"
35
+ Requires-Dist: qbraid-core[compute]>=0.6.55; extra == "compute"
36
36
  Provides-Extra: envs
37
- Requires-Dist: qbraid-core[environments]>=0.6.54; extra == "envs"
37
+ Requires-Dist: qbraid-core[environments]>=0.6.55; 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.54
5
+ qbraid-core>=0.6.55
6
6
 
7
7
  [compute]
8
- qbraid-core[compute]>=0.6.54
8
+ qbraid-core[compute]>=0.6.55
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.54
18
+ qbraid-core[environments]>=0.6.55
File without changes
File without changes
File without changes