conduct-cli 0.9.6__tar.gz → 0.9.8__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 (54) hide show
  1. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/PKG-INFO +1 -1
  2. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/pyproject.toml +1 -1
  3. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/main.py +38 -1
  4. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/PKG-INFO +1 -1
  5. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_switch.py +150 -0
  6. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/README.md +0 -0
  7. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/setup.cfg +0 -0
  8. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/setup.py +0 -0
  9. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/__init__.py +0 -0
  10. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/api.py +0 -0
  11. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/guard.py +0 -0
  12. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/guard_policy.md +0 -0
  13. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/guardmcp.py +0 -0
  14. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/__init__.py +0 -0
  15. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/base.py +0 -0
  16. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/posttooluse.py +0 -0
  17. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/precompact.py +0 -0
  18. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/pretooluse.py +0 -0
  19. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_parser.py +0 -0
  20. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_report_push.py +0 -0
  21. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_start.py +0 -0
  22. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/hooks/stop.py +0 -0
  23. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/log_util.py +0 -0
  24. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/mcp_server.py +0 -0
  25. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/memory.py +0 -0
  26. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/paxel.py +0 -0
  27. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli/tool_groups.py +0 -0
  28. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/SOURCES.txt +0 -0
  29. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/dependency_links.txt +0 -0
  30. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/entry_points.txt +0 -0
  31. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/requires.txt +0 -0
  32. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/top_level.txt +0 -0
  33. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_advisory_and_hook.py +0 -0
  34. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_api_client.py +0 -0
  35. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_bash_operator_signature.py +0 -0
  36. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_bash_scan_target.py +0 -0
  37. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_blast_radius.py +0 -0
  38. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_cli_matrix.py +0 -0
  39. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_cmd_run.py +0 -0
  40. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_command_word_matcher.py +0 -0
  41. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_conductguard_mcp_stdio.py +0 -0
  42. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_drain_daemon_health.py +0 -0
  43. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_guard_approvals.py +0 -0
  44. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_guard_policy.py +0 -0
  45. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_guard_savings.py +0 -0
  46. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_hook_dispatch.py +0 -0
  47. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_instruction_files.py +0 -0
  48. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_journal_drain.py +0 -0
  49. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_log_util.py +0 -0
  50. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_proxy_coverage.py +0 -0
  51. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_proxy_env.py +0 -0
  52. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_report_tool_coverage.py +0 -0
  53. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_signed_policy.py +0 -0
  54. {conduct_cli-0.9.6 → conduct_cli-0.9.8}/tests/test_token_lifecycle.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conduct-cli
3
- Version: 0.9.6
3
+ Version: 0.9.8
4
4
  Summary: CLI for Conduct AI — secure, govern, install agents, manage projects, run tests
5
5
  Author-email: Conduct AI <hello@conductai.ai>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "conduct-cli"
7
- version = "0.9.6"
7
+ version = "0.9.8"
8
8
  description = "CLI for Conduct AI — secure, govern, install agents, manage projects, run tests"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -576,7 +576,19 @@ def cmd_login(args):
576
576
  cfg.pop("api_key", None)
577
577
  _atomic_write(CONFIG_PATH, cfg)
578
578
 
579
- print(f"{GREEN}✓ Logged in{RESET} — workspace {GRAY}{result['workspace_id']}{RESET}")
579
+ # Fetch workspaces so we can display the current one by name and nudge
580
+ # the user if their account has more than one (cross-surface switch drift).
581
+ try:
582
+ _hdrs = {"Authorization": f"Bearer {result['agent_token']}", "Content-Type": "application/json"}
583
+ _workspaces = api.req("GET", f"{api_url}/projects", _hdrs) or []
584
+ except Exception:
585
+ _workspaces = []
586
+ _current = next((w for w in _workspaces if str(w.get("id")) == str(result["workspace_id"])), None)
587
+ _name = (_current or {}).get("name") or ""
588
+ if _name:
589
+ print(f"{GREEN}✓ Logged in{RESET} — workspace {BOLD}{_name}{RESET} {GRAY}({str(result['workspace_id'])[:8]}…){RESET}")
590
+ else:
591
+ print(f"{GREEN}✓ Logged in{RESET} — workspace {GRAY}{result['workspace_id']}{RESET}")
580
592
 
581
593
  # Auto-sync: register hooks + pull policy
582
594
  try:
@@ -588,6 +600,15 @@ def cmd_login(args):
588
600
  except Exception:
589
601
  pass
590
602
 
603
+ # Nudge if the account has multiple workspaces — the web UI and CLI hold
604
+ # workspace context independently, so users routinely forget which one
605
+ # the CLI is now targeting.
606
+ if len(_workspaces) > 1:
607
+ _others = [w.get("name","") for w in _workspaces if str(w.get("id")) != str(result["workspace_id"])]
608
+ _preview = ", ".join(o for o in _others[:3] if o)
609
+ print(f"\n {GRAY}You have {len(_workspaces)} workspaces. This CLI now targets:{RESET} {BOLD}{_name or result['workspace_id']}{RESET}")
610
+ print(f" {GRAY}Switch with:{RESET} {CYAN}conduct switch \"<name>\"{RESET} {GRAY}(others: {_preview}){RESET}")
611
+
591
612
 
592
613
  def cmd_agents(args):
593
614
  server, workspace_id, token = _require_auth(args)
@@ -1417,6 +1438,22 @@ def cmd_switch(args):
1417
1438
  new_id = str(chosen["id"])
1418
1439
  new_name = chosen["name"]
1419
1440
 
1441
+ # Re-mint agent token bound to the new workspace so server-side attribution
1442
+ # follows the switch. Without this, POSTs (discover, audit, heartbeats)
1443
+ # keep hitting the workspace the token was originally minted for.
1444
+ try:
1445
+ _r = api.req("POST", f"{server}/auth/switch-workspace", hdrs, {"workspace_id": new_id})
1446
+ if _r and _r.get("agent_token"):
1447
+ cfg["agent_token"] = _r["agent_token"]
1448
+ if _r.get("refresh_token"):
1449
+ cfg["refresh_token"] = _r["refresh_token"]
1450
+ import datetime as _dt
1451
+ cfg["token_expires_at"] = (_dt.datetime.now(_dt.timezone.utc) + _dt.timedelta(seconds=int(_r.get("expires_in", 28800)))).isoformat()
1452
+ except SystemExit:
1453
+ print(f" {YELLOW}⚠ Could not re-mint token for new workspace — falling back to config-only switch{RESET}")
1454
+ except Exception as e:
1455
+ print(f" {YELLOW}⚠ Token re-mint failed ({e}) — falling back to config-only switch{RESET}")
1456
+
1420
1457
  # Update ~/.conduct/config.json atomically
1421
1458
  cfg["workspace"] = new_id; cfg["workspace_id"] = new_id
1422
1459
  _atomic_write(CONFIG_PATH, cfg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conduct-cli
3
- Version: 0.9.6
3
+ Version: 0.9.8
4
4
  Summary: CLI for Conduct AI — secure, govern, install agents, manage projects, run tests
5
5
  Author-email: Conduct AI <hello@conductai.ai>
6
6
  License: MIT
@@ -227,3 +227,153 @@ def test_switch_accepts_api_url_key(tmp_path, capsys):
227
227
  out = capsys.readouterr().out
228
228
  assert "Not logged in" not in out
229
229
  assert "Engineering" in out
230
+
231
+
232
+ # ---------------------------------------------------------------------------
233
+ # Regression: `conduct login` prints workspace name (not just UUID) and a
234
+ # switch-hint when the account has more than one workspace. Cross-surface
235
+ # workspace drift (web-UI-switched, CLI still on old) was invisible before.
236
+ # ---------------------------------------------------------------------------
237
+
238
+ def test_login_shows_name_and_nudges_when_multiple_workspaces(tmp_path, capsys):
239
+ from conduct_cli import main as m
240
+
241
+ cfg_path = tmp_path / "config.json"
242
+ cfg_path.write_text(json.dumps({}))
243
+ args = _make_args(server=None, token=None)
244
+
245
+ fake_result = {
246
+ "agent_token": "cond_agt_testkey",
247
+ "workspace_id": "ef0a7e36-0000-0000-0000-000000000001",
248
+ }
249
+
250
+ with (
251
+ patch.object(m, "CONFIG_PATH", cfg_path),
252
+ patch.object(m, "_web_login_flow", return_value=fake_result),
253
+ patch.object(m.api, "req", return_value=_fake_workspaces()),
254
+ patch("conduct_cli.guard.cmd_guard_sync", return_value=None),
255
+ ):
256
+ m.cmd_login(args)
257
+
258
+ out = capsys.readouterr().out
259
+ # Current workspace displayed by name (not just UUID)
260
+ assert "Engineering" in out
261
+ # Nudge appears because account has >1 workspace
262
+ assert "conduct switch" in out
263
+ # Other workspace names surfaced in the preview
264
+ assert "Marketing" in out or "Eng Backup" in out
265
+
266
+
267
+ def test_login_omits_nudge_when_single_workspace(tmp_path, capsys):
268
+ from conduct_cli import main as m
269
+
270
+ cfg_path = tmp_path / "config.json"
271
+ cfg_path.write_text(json.dumps({}))
272
+ args = _make_args(server=None, token=None)
273
+
274
+ fake_result = {
275
+ "agent_token": "cond_agt_testkey",
276
+ "workspace_id": "ef0a7e36-0000-0000-0000-000000000001",
277
+ }
278
+ single_ws = [{"id": "ef0a7e36-0000-0000-0000-000000000001", "name": "Only", "owner_id": "u1", "workflow_count": 0}]
279
+
280
+ with (
281
+ patch.object(m, "CONFIG_PATH", cfg_path),
282
+ patch.object(m, "_web_login_flow", return_value=fake_result),
283
+ patch.object(m.api, "req", return_value=single_ws),
284
+ patch("conduct_cli.guard.cmd_guard_sync", return_value=None),
285
+ ):
286
+ m.cmd_login(args)
287
+
288
+ out = capsys.readouterr().out
289
+ assert "Only" in out
290
+ assert "conduct switch" not in out
291
+
292
+
293
+ # ---------------------------------------------------------------------------
294
+ # Fix A regression: cmd_switch must re-mint the agent token by calling
295
+ # POST /auth/switch-workspace so server-side attribution follows the local
296
+ # workspace flip. Without this, POSTs after switch keep hitting the
297
+ # original workspace.
298
+ # ---------------------------------------------------------------------------
299
+
300
+ def test_switch_remints_agent_token_via_endpoint(tmp_path, monkeypatch, capsys):
301
+ from conduct_cli import main as m
302
+ from conduct_cli import guard as g
303
+
304
+ cfg_path = tmp_path / "conduct" / "config.json"
305
+ cfg_path.parent.mkdir(parents=True)
306
+ cfg_path.write_text(json.dumps({
307
+ "api_url": "https://api.conductai.ai",
308
+ "agent_token": "cond_agt_ORIGINAL_engineering",
309
+ "workspace": "ef0a7e36-0000-0000-0000-000000000001",
310
+ }))
311
+
312
+ args = _make_args(workspace="Marketing")
313
+ remint_response = {
314
+ "agent_token": "cond_agt_NEW_marketing_scoped",
315
+ "refresh_token": "cond_ref_new_refresh",
316
+ "expires_in": 28800,
317
+ "workspace_id": "ab1b2c3d-0000-0000-0000-000000000002",
318
+ "user_id": "user_test",
319
+ }
320
+
321
+ def _api_req(method, url, hdrs, body=None, timeout=30):
322
+ if method == "GET" and url.endswith("/projects"):
323
+ return _fake_workspaces()
324
+ if method == "POST" and url.endswith("/auth/switch-workspace"):
325
+ assert body == {"workspace_id": "ab1b2c3d-0000-0000-0000-000000000002"}
326
+ return remint_response
327
+ raise AssertionError(f"unexpected call {method} {url}")
328
+
329
+ with (
330
+ patch.object(m, "CONFIG_PATH", cfg_path),
331
+ patch("pathlib.Path.home", return_value=tmp_path),
332
+ patch.object(m.api, "req", side_effect=_api_req),
333
+ patch.object(g, "_req", return_value={"version": "1", "rules": []}),
334
+ patch.object(g, "_save_policy"),
335
+ ):
336
+ m.cmd_switch(args)
337
+
338
+ updated_cfg = json.loads(cfg_path.read_text())
339
+ assert updated_cfg["agent_token"] == "cond_agt_NEW_marketing_scoped"
340
+ assert updated_cfg["refresh_token"] == "cond_ref_new_refresh"
341
+ assert updated_cfg["workspace_id"] == "ab1b2c3d-0000-0000-0000-000000000002"
342
+ assert "token_expires_at" in updated_cfg
343
+
344
+
345
+ def test_switch_falls_back_gracefully_when_remint_fails(tmp_path, monkeypatch, capsys):
346
+ """If the switch-workspace endpoint 401s (older server), config-only switch still applies."""
347
+ from conduct_cli import main as m
348
+ from conduct_cli import guard as g
349
+
350
+ cfg_path = tmp_path / "conduct" / "config.json"
351
+ cfg_path.parent.mkdir(parents=True)
352
+ cfg_path.write_text(json.dumps({
353
+ "api_url": "https://api.conductai.ai",
354
+ "agent_token": "cond_agt_ORIGINAL",
355
+ "workspace": "ef0a7e36-0000-0000-0000-000000000001",
356
+ }))
357
+ args = _make_args(workspace="Marketing")
358
+
359
+ def _api_req(method, url, hdrs, body=None, timeout=30):
360
+ if method == "GET" and url.endswith("/projects"):
361
+ return _fake_workspaces()
362
+ # Endpoint failure — mimic api.req's SystemExit on HTTP error
363
+ raise SystemExit(1)
364
+
365
+ with (
366
+ patch.object(m, "CONFIG_PATH", cfg_path),
367
+ patch("pathlib.Path.home", return_value=tmp_path),
368
+ patch.object(m.api, "req", side_effect=_api_req),
369
+ patch.object(g, "_req", return_value={"version": "1", "rules": []}),
370
+ patch.object(g, "_save_policy"),
371
+ ):
372
+ m.cmd_switch(args)
373
+
374
+ updated_cfg = json.loads(cfg_path.read_text())
375
+ # Token unchanged (fallback preserves the original) but workspace_id updated
376
+ assert updated_cfg["agent_token"] == "cond_agt_ORIGINAL"
377
+ assert updated_cfg["workspace_id"] == "ab1b2c3d-0000-0000-0000-000000000002"
378
+ out = capsys.readouterr().out
379
+ assert "falling back to config-only switch" in out
File without changes
File without changes
File without changes