conduct-cli 0.9.7__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.
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/PKG-INFO +1 -1
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/pyproject.toml +1 -1
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/main.py +16 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/PKG-INFO +1 -1
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_switch.py +89 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/README.md +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/setup.cfg +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/setup.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/__init__.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/api.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/guard.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/guard_policy.md +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/guardmcp.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/__init__.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/base.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/posttooluse.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/precompact.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/pretooluse.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_parser.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_report_push.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/session_start.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/hooks/stop.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/log_util.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/mcp_server.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/memory.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/paxel.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli/tool_groups.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/SOURCES.txt +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/dependency_links.txt +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/entry_points.txt +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/requires.txt +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/src/conduct_cli.egg-info/top_level.txt +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_advisory_and_hook.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_api_client.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_bash_operator_signature.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_bash_scan_target.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_blast_radius.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_cli_matrix.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_cmd_run.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_command_word_matcher.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_conductguard_mcp_stdio.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_drain_daemon_health.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_guard_approvals.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_guard_policy.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_guard_savings.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_hook_dispatch.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_instruction_files.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_journal_drain.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_log_util.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_proxy_coverage.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_proxy_env.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_report_tool_coverage.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_signed_policy.py +0 -0
- {conduct_cli-0.9.7 → conduct_cli-0.9.8}/tests/test_token_lifecycle.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "conduct-cli"
|
|
7
|
-
version = "0.9.
|
|
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" }
|
|
@@ -1438,6 +1438,22 @@ def cmd_switch(args):
|
|
|
1438
1438
|
new_id = str(chosen["id"])
|
|
1439
1439
|
new_name = chosen["name"]
|
|
1440
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
|
+
|
|
1441
1457
|
# Update ~/.conduct/config.json atomically
|
|
1442
1458
|
cfg["workspace"] = new_id; cfg["workspace_id"] = new_id
|
|
1443
1459
|
_atomic_write(CONFIG_PATH, cfg)
|
|
@@ -288,3 +288,92 @@ def test_login_omits_nudge_when_single_workspace(tmp_path, capsys):
|
|
|
288
288
|
out = capsys.readouterr().out
|
|
289
289
|
assert "Only" in out
|
|
290
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
|
|
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
|