qbraid-cli 0.17.5__tar.gz → 0.17.6__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 (84) hide show
  1. {qbraid_cli-0.17.5/qbraid_cli.egg-info → qbraid_cli-0.17.6}/PKG-INFO +4 -4
  2. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/pyproject.toml +4 -4
  3. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/app.py +192 -38
  4. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6/qbraid_cli.egg-info}/PKG-INFO +4 -4
  5. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli.egg-info/requires.txt +3 -3
  6. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/LICENSE +0 -0
  7. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/README.md +0 -0
  8. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/__init__.py +0 -0
  9. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/_build_info.py +0 -0
  10. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/_version.py +0 -0
  11. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/account/__init__.py +0 -0
  12. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/account/app.py +0 -0
  13. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/admin/__init__.py +0 -0
  14. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/admin/app.py +0 -0
  15. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/admin/headers.py +0 -0
  16. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/admin/validation.py +0 -0
  17. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/__init__.py +0 -0
  18. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/keep_alive.py +0 -0
  19. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/permission_response.py +0 -0
  20. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/provider_children.py +0 -0
  21. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/queue.py +0 -0
  22. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/agents/work.py +0 -0
  23. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/ai/__init__.py +0 -0
  24. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/ai/app.py +0 -0
  25. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/ai/token.py +0 -0
  26. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/artifacts/__init__.py +0 -0
  27. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/artifacts/app.py +0 -0
  28. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/artifacts/mermaid.py +0 -0
  29. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/artifacts/pele.LICENSE +0 -0
  30. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/artifacts/pele.global.js +0 -0
  31. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/comms/__init__.py +0 -0
  32. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/comms/app.py +0 -0
  33. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/__init__.py +0 -0
  34. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/app.py +0 -0
  35. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/instances.py +0 -0
  36. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/profiles.py +0 -0
  37. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/server.py +0 -0
  38. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/compute/ssh.py +0 -0
  39. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/configure/__init__.py +0 -0
  40. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/configure/actions.py +0 -0
  41. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/configure/app.py +0 -0
  42. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/devices/__init__.py +0 -0
  43. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/devices/app.py +0 -0
  44. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/devices/validation.py +0 -0
  45. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/__init__.py +0 -0
  46. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/activate.py +0 -0
  47. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/app.py +0 -0
  48. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/create.py +0 -0
  49. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/data_handling.py +0 -0
  50. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/groups.py +0 -0
  51. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/publish.py +0 -0
  52. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/registry.py +0 -0
  53. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/envs/share.py +0 -0
  54. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/exceptions.py +0 -0
  55. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/handlers.py +0 -0
  56. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/jobs/__init__.py +0 -0
  57. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/jobs/app.py +0 -0
  58. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/jobs/groups.py +0 -0
  59. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/kernels/__init__.py +0 -0
  60. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/kernels/app.py +0 -0
  61. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/lab/__init__.py +0 -0
  62. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/lab/app.py +0 -0
  63. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/main.py +0 -0
  64. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/pip/__init__.py +0 -0
  65. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/pip/app.py +0 -0
  66. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/pip/hooks.py +0 -0
  67. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/projects/__init__.py +0 -0
  68. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/projects/app.py +0 -0
  69. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/py.typed +0 -0
  70. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/skills/__init__.py +0 -0
  71. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/skills/app.py +0 -0
  72. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/troubleshoot/__init__.py +0 -0
  73. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/troubleshoot/app.py +0 -0
  74. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli/upgrade.py +0 -0
  75. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli.egg-info/SOURCES.txt +0 -0
  76. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli.egg-info/dependency_links.txt +0 -0
  77. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli.egg-info/entry_points.txt +0 -0
  78. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/qbraid_cli.egg-info/top_level.txt +0 -0
  79. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/setup.cfg +0 -0
  80. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/tests/test_cli_e2e.py +0 -0
  81. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/tests/test_register_client.py +0 -0
  82. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/tests/test_status_colors.py +0 -0
  83. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/tests/test_upgrade.py +0 -0
  84. {qbraid_cli-0.17.5 → qbraid_cli-0.17.6}/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.5
3
+ Version: 0.17.6
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.60
33
+ Requires-Dist: qbraid-core>=0.6.61
34
34
  Provides-Extra: compute
35
- Requires-Dist: qbraid-core[compute]>=0.6.60; extra == "compute"
35
+ Requires-Dist: qbraid-core[compute]>=0.6.61; extra == "compute"
36
36
  Provides-Extra: envs
37
- Requires-Dist: qbraid-core[environments]>=0.6.60; extra == "envs"
37
+ Requires-Dist: qbraid-core[environments]>=0.6.61; 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.5"
7
+ version = "0.17.6"
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.60",
35
+ "qbraid-core>=0.6.61",
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.60"]
47
- envs = ["qbraid-core[environments]>=0.6.60"]
46
+ compute = ["qbraid-core[compute]>=0.6.61"]
47
+ envs = ["qbraid-core[environments]>=0.6.61"]
48
48
  dev = ["isort", "black", "pytest", "pytest-cov", "pytest-asyncio"]
49
49
 
50
50
  [project.scripts]
@@ -1507,6 +1507,48 @@ def agents_update(
1507
1507
  # =============================================================================
1508
1508
 
1509
1509
 
1510
+ def _session_is_live(session) -> bool:
1511
+ """Not stopped or errored (rows a resumed conversation leaves behind are)."""
1512
+ status = getattr(session, "status", None)
1513
+ return getattr(status, "value", status) not in ("stopped", "error")
1514
+
1515
+
1516
+ def _kill_matches(registry, target: str) -> list:
1517
+ """The sessions a ``kill`` target names: one, none, or several it can't tell apart.
1518
+
1519
+ A PID matches its rows. Otherwise newer Core resolves the target
1520
+ (``resolve_session``): a name shared with older stopped rows is the one live
1521
+ row, and only two or more live namesakes are ambiguous. Core's other
1522
+ ambiguity (an id prefix of several sessions) comes back with every
1523
+ candidate, stopped ones included, so the caller refuses it.
1524
+ """
1525
+ if target.isdigit():
1526
+ by_pid = [s for s in registry.load_registry().sessions if s.pid == int(target)]
1527
+ if by_pid:
1528
+ return by_pid
1529
+ resolve = _core_method(registry, "resolve_session")
1530
+ if resolve is not None:
1531
+ try:
1532
+ found = resolve(target)
1533
+ except Exception as err: # pylint: disable=broad-exception-caught
1534
+ if type(err).__name__ != "AgentSessionAmbiguousError":
1535
+ raise
1536
+ return list(getattr(err, "candidates", None) or [])
1537
+ return [found] if found is not None else []
1538
+ matches = [
1539
+ s
1540
+ for s in registry.load_registry().sessions
1541
+ if (
1542
+ s.session_id == target
1543
+ or s.session_id.startswith(target)
1544
+ or (s.tmux_window and s.tmux_window == target)
1545
+ or (s.terminal_name and s.terminal_name == target)
1546
+ )
1547
+ ]
1548
+ live = [s for s in matches if _session_is_live(s)]
1549
+ return live if len(matches) > 1 and len(live) == 1 else matches
1550
+
1551
+
1510
1552
  @agents_app.command("kill")
1511
1553
  def agents_kill(
1512
1554
  target: str = typer.Argument(..., help="Agent name, ID prefix, or PID"),
@@ -1529,37 +1571,22 @@ def agents_kill(
1529
1571
  return
1530
1572
 
1531
1573
  registry = AgentSessionRegistryManager()
1532
- all_sessions = registry.load_registry().sessions
1533
1574
 
1534
- # Try to find sessions matching the target
1575
+ # Find the session the target names:
1535
1576
  # 1. Exact PID match (if target is numeric)
1536
- # 2. Session ID / prefix match
1537
- # 3. Name match (tmux_window or terminal_name)
1538
- matches = []
1539
- target_is_pid = target.isdigit()
1540
-
1541
- if target_is_pid:
1542
- pid_val = int(target)
1543
- matches = [s for s in all_sessions if s.pid == pid_val]
1544
-
1545
- if not matches:
1546
- matches = [
1547
- s
1548
- for s in all_sessions
1549
- if (
1550
- s.session_id == target
1551
- or s.session_id.startswith(target)
1552
- or (s.tmux_window and s.tmux_window == target)
1553
- or (s.terminal_name and s.terminal_name == target)
1554
- )
1555
- ]
1577
+ # 2. Core's resolver: exact id, an exact name preferring the one live
1578
+ # row over stopped namesakes, then a unique id prefix (core #771: an
1579
+ # older stopped row of the same name no longer makes it ambiguous)
1580
+ # 3. Older Core: the same preference here
1581
+ matches = _kill_matches(registry, target)
1556
1582
 
1557
1583
  if not matches:
1558
1584
  _stop_refused(f"No session found matching '{target}'.", as_json, "SESSION_NOT_FOUND")
1559
1585
 
1560
- # If multiple matches, show filtered picker
1586
+ # Several LIVE sessions share the target: a person at a terminal picks
1587
+ # one. Otherwise (no terminal, or a stopped row among them) refused at once.
1561
1588
  if len(matches) > 1:
1562
- if as_json or not _can_ask():
1589
+ if as_json or not _can_ask() or not all(_session_is_live(s) for s in matches):
1563
1590
  _stop_refused(
1564
1591
  "Multiple sessions match; use a complete, exact session ID.", as_json, "AMBIGUOUS_SESSION"
1565
1592
  )
@@ -2152,6 +2179,44 @@ class TrustTool(str, Enum):
2152
2179
  CODEX = "codex"
2153
2180
 
2154
2181
 
2182
+ def _remote_agent_refusal(compute: str, folder: Optional[str], tool: str, no: bool) -> str:
2183
+ """Why an agent may not run ``trust-folder --compute``, and, when an agent
2184
+ may trust that folder at all, the launch that records it as its own."""
2185
+ import importlib # pylint: disable=import-outside-toplevel
2186
+ import shlex # pylint: disable=import-outside-toplevel
2187
+
2188
+ try:
2189
+ trust_module = importlib.import_module("qbraid_core.services.agents.trust")
2190
+ except ImportError:
2191
+ trust_module = None
2192
+ if no:
2193
+ # Only the person records a "no": no launch says it for an agent.
2194
+ return getattr(
2195
+ trust_module,
2196
+ "AGENT_CANNOT_SAY_NO",
2197
+ 'Only the person records a "no" for a folder; an agent can only trust an ordinary '
2198
+ "folder the person has not decided on.",
2199
+ )
2200
+ refusal = "Only the person decides here: over SSH the remote would record it as theirs."
2201
+ if folder and folder.rstrip("/\\") == "~":
2202
+ # Home stays the person's: no launch trusts it for an agent either.
2203
+ return (
2204
+ refusal
2205
+ + " "
2206
+ + getattr(
2207
+ trust_module,
2208
+ "AGENT_CANNOT_TRUST_HOME",
2209
+ "An agent can't trust the home folder; only the person can, with a deliberate tick.",
2210
+ )
2211
+ )
2212
+ where = f" --cwd {shlex.quote(folder)}" if folder else ""
2213
+ return (
2214
+ f"{refusal} An agent may trust an ordinary folder there as its own by launching into it: "
2215
+ f"qbraid agents launch --compute {shlex.quote(compute)} --tool {shlex.quote(tool)}"
2216
+ f"{where} --trust-folder"
2217
+ )
2218
+
2219
+
2155
2220
  def _trust_folder_remote(compute: str, folder: Optional[str], tool: str, no: bool, json_output: bool) -> None:
2156
2221
  """``trust-folder --compute``: the person's decision, recorded on the remote.
2157
2222
 
@@ -2159,12 +2224,15 @@ def _trust_folder_remote(compute: str, folder: Optional[str], tool: str, no: boo
2159
2224
  is required (the question is asked here, never skipped with --yes), since a
2160
2225
  remote launch is always unattended and this is the one way to unblock
2161
2226
  NEEDS_TRUST_DECISION there. The remote runs its own ``trust-folder --yes
2162
- --json``; its refusals (a folder above home, the root) come back as-is.
2227
+ --json``, which it would record as the person's, so an agent is pointed at
2228
+ ``launch --compute --trust-folder`` instead: the destination records that
2229
+ as the agent's (``launch-agent-trust-v1``). The remote's refusals (a
2230
+ folder above home, the root) come back as-is.
2163
2231
  """
2164
2232
  import shlex # pylint: disable=import-outside-toplevel
2165
2233
 
2166
2234
  if _caller_agent_reason() or _calling_session(_get_registry(), refuse_ambiguous=False):
2167
- typer.echo("Only the person decides whether to trust a folder; an agent cannot.", err=True)
2235
+ typer.echo(_remote_agent_refusal(compute, folder, tool, no), err=True)
2168
2236
  raise typer.Exit(1)
2169
2237
  if _bad_alias(compute):
2170
2238
  typer.echo(f"--compute: invalid SSH alias {compute!r}.", err=True)
@@ -2212,8 +2280,10 @@ def _trust_folder_remote(compute: str, folder: Optional[str], tool: str, no: boo
2212
2280
  def agents_trust_folder(
2213
2281
  folder: Optional[str] = typer.Argument(None, help="Folder to decide about (default: here)."),
2214
2282
  tool_choice: TrustTool = typer.Option(TrustTool.CLAUDE, "--tool", help="Agent whose trust to set."),
2215
- no: bool = typer.Option(False, "--no", help="Undo: stop trusting your home folder."),
2216
- yes: bool = typer.Option(False, "--yes", "-y", help="Skip the confirmation question."),
2283
+ no: bool = typer.Option(False, "--no", help="Record a no, or undo trusting home (yours only)."),
2284
+ yes: bool = typer.Option(
2285
+ False, "--yes", "-y", help="Skip the confirmation question (an agent is never asked)."
2286
+ ),
2217
2287
  json_output: bool = typer.Option(False, "--json", help="Print the recorded decision."),
2218
2288
  compute: Optional[str] = typer.Option(
2219
2289
  None,
@@ -2232,11 +2302,16 @@ def agents_trust_folder(
2232
2302
  own settings, hooks and MCP servers run. For
2233
2303
  your home folder the decision is standing (it covers every launch there,
2234
2304
  including unattended ones) and is recorded with when and how; undo it with
2235
- --no. Only you can decide: an agent calling this is refused.
2305
+ --no.
2306
+
2307
+ An agent calling this may trust an ordinary folder you have not decided
2308
+ on, without a question; it is recorded as the agent's, never as yours.
2309
+ Your home folder, a folder you said no to, and --no stay yours alone.
2236
2310
 
2237
2311
  With --compute the decision is recorded on that server (the folder path is
2238
2312
  the remote one): a launch there with ``--compute`` has nobody at its
2239
- terminal and fails with NEEDS_TRUST_DECISION until you decide.
2313
+ terminal and fails with NEEDS_TRUST_DECISION until you decide. Only you
2314
+ decide with --compute; an agent launches with --compute and --trust-folder.
2240
2315
  """
2241
2316
  if compute is not None:
2242
2317
  _trust_folder_remote(compute, folder, tool_choice.value, no, json_output)
@@ -2254,15 +2329,26 @@ def agents_trust_folder(
2254
2329
  import importlib
2255
2330
 
2256
2331
  trust_module = importlib.import_module("qbraid_core.services.agents.trust")
2257
- caller_is_agent = getattr(trust_module, "_caller_is_agent", None)
2258
- if callable(caller_is_agent) and caller_is_agent():
2259
- # Refused before any warning or question: the decision is the person's.
2260
- typer.echo("Only the person decides whether to trust a folder; an agent cannot.", err=True)
2332
+ # Core's own test for an agent deciding (#756), else its older caller test.
2333
+ agent_deciding = getattr(trust_module, "_agent_deciding", None) or getattr(
2334
+ trust_module, "_caller_is_agent", None
2335
+ )
2336
+ agent = callable(agent_deciding) and bool(agent_deciding())
2337
+ if agent and not hasattr(trust_module, "agent_trust_folder"):
2338
+ # A Core before 0.6.61 would record an agent's trust as the person's.
2339
+ typer.echo(
2340
+ "Only the person decides whether to trust a folder with this qbraid-core; "
2341
+ "an agent may trust an ordinary folder with a newer qbraid-core (0.6.61+).",
2342
+ err=True,
2343
+ )
2261
2344
  raise typer.Exit(1)
2262
2345
  tool = tool_choice.value
2263
2346
  target = os.path.abspath(os.path.expanduser(folder or os.getcwd()))
2264
2347
  trusted = not no
2265
- if trusted:
2348
+ # An agent is never asked and never shown the home warning: Core trusts an
2349
+ # ordinary folder as the agent's and refuses home, the person's "no" and an
2350
+ # agent's --no with the reason (#469).
2351
+ if trusted and not agent:
2266
2352
  # Everything that would refuse is checked before the person is asked.
2267
2353
  try:
2268
2354
  plan = folder_trust_target(tool, target)
@@ -2313,6 +2399,8 @@ def agents_trust_folder(
2313
2399
  shown = result.get("trustedAs") or result["folder"]
2314
2400
  if not result["trusted"]:
2315
2401
  typer.echo(f"{result['folder']} is no longer trusted by your choice.")
2402
+ elif result.get("by") == "agent":
2403
+ typer.echo(f"{shown} is trusted for {tool}, recorded as an agent's decision.")
2316
2404
  elif result["standing"]:
2317
2405
  typer.echo(f"{shown} is trusted by your choice. Undo: qbraid agents trust-folder ~ --no")
2318
2406
  else:
@@ -2892,6 +2980,8 @@ def agents_launch(
2892
2980
  "Answer the agent's 'trust this folder?' prompt now (Claude, Codex), so a detached "
2893
2981
  "agent does not stop at it. The answer is remembered for later launches and "
2894
2982
  "resumes. Trusting a folder lets its own settings, hooks and MCP servers run. "
2983
+ "An agent may trust an ordinary folder (recorded as its own), never your home "
2984
+ "folder or one you said no to; also with --compute. "
2895
2985
  "Default: Claude trusts the folder, except a fresh --repo clone; Codex asks."
2896
2986
  ),
2897
2987
  ),
@@ -2985,10 +3075,10 @@ def agents_launch(
2985
3075
  if not compute or str(uuid.UUID(request_id)) != request_id:
2986
3076
  raise AgentLauncherError("--request-id requires --compute and a canonical UUID.")
2987
3077
 
2988
- if compute and (trust_folder is not None or skip_bypass_confirmation):
3078
+ if compute and skip_bypass_confirmation:
2989
3079
  raise AgentLauncherError(
2990
- "--trust-folder and --skip-bypass-confirmation are not yet supported for remote "
2991
- "launches; answer the prompts in the agent's terminal."
3080
+ "--skip-bypass-confirmation is not yet supported for remote launches; answer "
3081
+ "the prompt in the agent's terminal."
2992
3082
  )
2993
3083
 
2994
3084
  if compute and backend != TerminalBackend.AUTO:
@@ -3009,6 +3099,9 @@ def agents_launch(
3009
3099
  tags=tag,
3010
3100
  **links,
3011
3101
  **_request_id_kwargs(launcher.remote_launch, request_id),
3102
+ # The destination records a person's answer (launch-trust-folder-v1)
3103
+ # or an agent's trust of an ordinary folder (launch-agent-trust-v1).
3104
+ **_prompt_answer_kwargs(launcher.remote_launch, trust_folder),
3012
3105
  **_approval_kwargs(launcher.remote_launch, approval.value if approval else None),
3013
3106
  **_hook_trust_kwargs(launcher.remote_launch, True if trust_hooks else None),
3014
3107
  **_execution_kwargs(launcher.remote_launch, execution_mode.value if execution_mode else None),
@@ -3165,6 +3258,33 @@ def _interactive_resume(console_: Console) -> str:
3165
3258
  return selected
3166
3259
 
3167
3260
 
3261
+ def _backend_notice(session) -> Optional[str]:
3262
+ """Core's note that a resume left the session's recorded backend (#470,
3263
+ qbraid-core 0.6.62), or None: also on an older Core, which has no
3264
+ ``backend_notice``."""
3265
+ notice = getattr(session, "backend_notice", None)
3266
+ if not isinstance(notice, str):
3267
+ return None
3268
+ # Never a terminal control sequence: printed as it is to the person.
3269
+ return _printable(notice).strip() or None
3270
+
3271
+
3272
+ def _resume_json_refused(reason: str) -> None:
3273
+ """``resume --json`` never asks a question: refused (exit 2), the reason
3274
+ on stderr."""
3275
+ typer.echo(reason, err=True)
3276
+ raise typer.Exit(code=2)
3277
+
3278
+
3279
+ def _resumed_json(session, already_running: bool) -> dict:
3280
+ """``resume --json``: the session as Core serializes it, with
3281
+ ``backendNotice`` (null when it resumed where it ran)."""
3282
+ data = session.model_dump(mode="json", by_alias=True, exclude_none=True)
3283
+ data["backendNotice"] = _backend_notice(session)
3284
+ data["alreadyRunning"] = bool(already_running)
3285
+ return data
3286
+
3287
+
3168
3288
  @agents_app.command("resume")
3169
3289
  def agents_resume(
3170
3290
  backend: TerminalBackend = typer.Option(
@@ -3217,6 +3337,9 @@ def agents_resume(
3217
3337
  ),
3218
3338
  ),
3219
3339
  compute: Optional[str] = typer.Option(None, "--compute", "-c", help="SSH alias for remote compute"),
3340
+ json_output: bool = typer.Option(
3341
+ False, "--json", help="Print the resumed session as JSON, with backendNotice."
3342
+ ),
3220
3343
  ):
3221
3344
  """Resume a previous agent session.
3222
3345
 
@@ -3230,6 +3353,10 @@ def agents_resume(
3230
3353
  the person is asked (default No). Without a terminal it refuses unless
3231
3354
  ``--yes`` is given. An agent must never pass ``--yes`` on its own judgement:
3232
3355
  only after the person has confirmed that the old Lab is closed or restarted.
3356
+
3357
+ When the session's recorded backend is not available here (tmux missing,
3358
+ or no Lab), it resumes on this machine's default and says so
3359
+ (``backendNotice`` in ``--json``).
3233
3360
  """
3234
3361
  try:
3235
3362
  from qbraid_core.services.agents import AgentLauncherError
@@ -3264,6 +3391,10 @@ def agents_resume(
3264
3391
  flags += " --trust-hooks"
3265
3392
  if trust_folder is not None:
3266
3393
  flags += " --trust-folder" if trust_folder else " --no-trust-folder"
3394
+ if json_output:
3395
+ # Plain print: the console would wrap a long JSON line.
3396
+ print(_ssh_cmd(compute, f"qbraid agents resume {shlex.quote(session_id)}{flags} --json"))
3397
+ return
3267
3398
  # markup=False -- see agents_status.
3268
3399
  console.print(
3269
3400
  _ssh_cmd(compute, f"qbraid agents resume {shlex.quote(session_id)}{flags}"),
@@ -3273,6 +3404,8 @@ def agents_resume(
3273
3404
 
3274
3405
  # Interactive mode if no session_id provided
3275
3406
  if session_id is None:
3407
+ if json_output:
3408
+ _resume_json_refused("--json needs a session id: the session picker is interactive.")
3276
3409
  session_id = _interactive_resume(console)
3277
3410
 
3278
3411
  launcher = _backend_launcher(backend)
@@ -3309,6 +3442,11 @@ def agents_resume(
3309
3442
  active_sid = parts[1]
3310
3443
  tmux_sess = parts[2]
3311
3444
  tmux_win = parts[3]
3445
+ if json_output:
3446
+ _resume_json_refused(
3447
+ f"Session {_printable(active_sid)[:8]} is currently active in tmux window "
3448
+ f"'{_printable(tmux_win)}'; attach to it or fork it without --json."
3449
+ )
3312
3450
 
3313
3451
  console.print(
3314
3452
  f"[yellow]Session {active_sid[:8]} is currently active "
@@ -3384,6 +3522,8 @@ def agents_resume(
3384
3522
 
3385
3523
  elif "Multiple sessions match" not in err_msg:
3386
3524
  raise
3525
+ elif json_output:
3526
+ _resume_json_refused(f"{_printable(err_msg)} (--json does not show the session picker.)")
3387
3527
  else:
3388
3528
  # Only an ambiguous prefix reaches the picker. A completed fork
3389
3529
  # used to fall through to it, find no matches and exit 1 after
@@ -3442,6 +3582,10 @@ def agents_resume(
3442
3582
  **_execution_kwargs(launcher.resume, execution_mode.value if execution_mode else None),
3443
3583
  )
3444
3584
 
3585
+ if json_output:
3586
+ print(json.dumps(_resumed_json(session, _already_running(session, resume_started))))
3587
+ return
3588
+
3445
3589
  if _already_running(session, resume_started):
3446
3590
  name_val = session.terminal_name or session.tmux_window
3447
3591
  label = f"{session.session_id[:8]}" + (f" ({escape(name_val)})" if name_val else "")
@@ -3475,16 +3619,26 @@ def agents_resume(
3475
3619
  border_style="blue",
3476
3620
  )
3477
3621
  console.print(panel)
3622
+ notice = _backend_notice(session)
3623
+ if notice:
3624
+ console.print(f"[yellow]Note:[/yellow] {escape(notice)}", highlight=False)
3478
3625
  console.print()
3479
3626
  console.print("[dim]Attach with:[/dim]")
3480
3627
  _startup_notice(session)
3481
3628
 
3482
3629
  except AgentLauncherError as e:
3630
+ if json_output:
3631
+ # stdout stays JSON (or nothing): the error goes to stderr.
3632
+ typer.echo(_printable(e), err=True)
3633
+ raise typer.Exit(code=1)
3483
3634
  console.print(Panel(str(e), title="Resume Error", border_style="red"))
3484
3635
  raise typer.Exit(code=1)
3485
3636
  except (typer.Exit, SystemExit):
3486
3637
  raise
3487
3638
  except Exception as e:
3639
+ if json_output:
3640
+ typer.echo(_printable(e), err=True)
3641
+ raise typer.Exit(code=1)
3488
3642
  handle_error(message=str(e))
3489
3643
  raise typer.Exit(code=1)
3490
3644
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qbraid-cli
3
- Version: 0.17.5
3
+ Version: 0.17.6
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.60
33
+ Requires-Dist: qbraid-core>=0.6.61
34
34
  Provides-Extra: compute
35
- Requires-Dist: qbraid-core[compute]>=0.6.60; extra == "compute"
35
+ Requires-Dist: qbraid-core[compute]>=0.6.61; extra == "compute"
36
36
  Provides-Extra: envs
37
- Requires-Dist: qbraid-core[environments]>=0.6.60; extra == "envs"
37
+ Requires-Dist: qbraid-core[environments]>=0.6.61; 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.60
5
+ qbraid-core>=0.6.61
6
6
 
7
7
  [compute]
8
- qbraid-core[compute]>=0.6.60
8
+ qbraid-core[compute]>=0.6.61
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.60
18
+ qbraid-core[environments]>=0.6.61
File without changes
File without changes
File without changes