chattermate-cli 0.7.0__tar.gz → 0.8.0__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 (38) hide show
  1. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/PKG-INFO +5 -1
  2. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/README.md +4 -0
  3. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/__init__.py +1 -1
  4. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/auth.py +43 -11
  5. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/PKG-INFO +5 -1
  6. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/SOURCES.txt +1 -0
  7. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/pyproject.toml +1 -1
  8. chattermate_cli-0.8.0/tests/test_auth.py +142 -0
  9. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/LICENSE +0 -0
  10. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/client.py +0 -0
  11. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/__init__.py +0 -0
  12. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/agent.py +0 -0
  13. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/ai.py +0 -0
  14. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/customization.py +0 -0
  15. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/help_center.py +0 -0
  16. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/knowledge.py +0 -0
  17. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/lead_capture.py +0 -0
  18. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/ticketing.py +0 -0
  19. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/widget.py +0 -0
  20. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/workflow.py +0 -0
  21. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/config.py +0 -0
  22. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/context.py +0 -0
  23. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/main.py +0 -0
  24. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli/mcp_server.py +0 -0
  25. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/dependency_links.txt +0 -0
  26. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/entry_points.txt +0 -0
  27. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/requires.txt +0 -0
  28. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/top_level.txt +0 -0
  29. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/setup.cfg +0 -0
  30. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_ai.py +0 -0
  31. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_client.py +0 -0
  32. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_customization.py +0 -0
  33. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_help_center.py +0 -0
  34. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_knowledge.py +0 -0
  35. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_lead_capture.py +0 -0
  36. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_mcp.py +0 -0
  37. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_ticketing.py +0 -0
  38. {chattermate_cli-0.7.0 → chattermate_cli-0.8.0}/tests/test_widget.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chattermate-cli
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: ChatterMate CLI and MCP server — sign up, authenticate, and configure agents, workflows and knowledge from the terminal or an AI agent.
5
5
  Author: ChatterMate
6
6
  License: AGPL-3.0-or-later
@@ -48,6 +48,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
48
48
  # Create an organization + admin (community signup), or log in to an existing one
49
49
  chattermate signup
50
50
  chattermate login --email you@acme.com
51
+ # Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
52
+ chattermate login --token
51
53
 
52
54
  chattermate whoami
53
55
 
@@ -83,6 +85,8 @@ Two credentials are supported:
83
85
  the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
84
86
  - **JWT login** — `chattermate login` stores access + refresh tokens in
85
87
  `~/.chattermate/config.json` (mode `600`) and refreshes automatically.
88
+ `chattermate login --token` stores a PAT there instead, read from a hidden prompt —
89
+ the way to log in for accounts that use Google or Microsoft sign-in.
86
90
 
87
91
  ## MCP server (AI agents)
88
92
 
@@ -30,6 +30,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
30
30
  # Create an organization + admin (community signup), or log in to an existing one
31
31
  chattermate signup
32
32
  chattermate login --email you@acme.com
33
+ # Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
34
+ chattermate login --token
33
35
 
34
36
  chattermate whoami
35
37
 
@@ -65,6 +67,8 @@ Two credentials are supported:
65
67
  the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
66
68
  - **JWT login** — `chattermate login` stores access + refresh tokens in
67
69
  `~/.chattermate/config.json` (mode `600`) and refreshes automatically.
70
+ `chattermate login --token` stores a PAT there instead, read from a hidden prompt —
71
+ the way to log in for accounts that use Google or Microsoft sign-in.
68
72
 
69
73
  ## MCP server (AI agents)
70
74
 
@@ -16,4 +16,4 @@ You should have received a copy of the GNU Affero General Public License
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>
17
17
  """
18
18
 
19
- __version__ = "0.7.0"
19
+ __version__ = "0.8.0"
@@ -24,6 +24,7 @@ import typer
24
24
  from rich.table import Table
25
25
 
26
26
  from .. import config
27
+ from ..client import PAT_PREFIX
27
28
  from ..context import console, get_client, output, print_error, run
28
29
 
29
30
  token_app = typer.Typer(no_args_is_help=True, help="Manage personal access tokens (PATs).")
@@ -41,13 +42,24 @@ def _store_session(client, user: dict) -> None:
41
42
 
42
43
 
43
44
  def login(
44
- email: str = typer.Option(..., "--email", "-e", prompt=True, help="Account email."),
45
- password: str = typer.Option(
46
- ..., "--password", "-p", prompt=True, hide_input=True, help="Account password."
45
+ email: Optional[str] = typer.Option(None, "--email", "-e", help="Account email."),
46
+ password: Optional[str] = typer.Option(None, "--password", "-p", help="Account password."),
47
+ with_token: bool = typer.Option(
48
+ False, "--token",
49
+ help="Log in with a personal access token (cmat_...) from the dashboard. "
50
+ "For accounts that sign in with Google or Microsoft.",
47
51
  ),
48
52
  as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
49
53
  ):
50
- """Log in and store JWT credentials in ~/.chattermate/config.json."""
54
+ """Log in and store credentials in ~/.chattermate/config.json."""
55
+ if with_token:
56
+ if email or password:
57
+ print_error("--token can't be combined with --email or --password.")
58
+ raise typer.Exit(code=1)
59
+ _login_with_token(as_json)
60
+ return
61
+ email = email or typer.prompt("Email")
62
+ password = password or typer.prompt("Password", hide_input=True)
51
63
  client = get_client(require_auth=False)
52
64
  data = run(lambda: client.login(email, password))
53
65
  user = data.get("user", {}) if isinstance(data, dict) else {}
@@ -59,6 +71,28 @@ def login(
59
71
  console.print("Tip: create a long-lived token for AI agents with 'chattermate token create'.")
60
72
 
61
73
 
74
+ def _login_with_token(as_json: bool) -> None:
75
+ """Store a personal access token once the API accepts it.
76
+
77
+ The token is read from a hidden prompt (never argv, so it stays out of shell
78
+ history and process listings) and checked with whoami before it is saved.
79
+ """
80
+ token = typer.prompt("Access token", hide_input=True).strip()
81
+ if not token.startswith(PAT_PREFIX):
82
+ print_error(f"That doesn't look like an access token (they start with '{PAT_PREFIX}').")
83
+ raise typer.Exit(code=1)
84
+ client = get_client(require_auth=False)
85
+ client.token, client.refresh_token = token, None
86
+ user = run(client.whoami)
87
+ # Drop any JWT session first: a leftover refresh token must not outlive the switch.
88
+ config.clear_auth()
89
+ _store_session(client, user if isinstance(user, dict) else {})
90
+ if as_json:
91
+ output(user, True)
92
+ else:
93
+ console.print(f"[green]Logged in[/green] as {user.get('email')}")
94
+
95
+
62
96
  def signup(
63
97
  name: str = typer.Option(..., "--name", prompt=True, help="Organization name."),
64
98
  domain: str = typer.Option(..., "--domain", prompt=True, help="Organization domain, e.g. acme.com."),
@@ -76,8 +110,8 @@ def signup(
76
110
  ),
77
111
  otp: Optional[str] = typer.Option(
78
112
  None, "--otp",
79
- help="One-time code emailed to the admin address (on a localhost instance the test "
80
- "code is 123456). If omitted you'll be prompted. Ignored with --community.",
113
+ help="One-time code emailed to the admin address. If omitted you'll be prompted. "
114
+ "Ignored with --community.",
81
115
  ),
82
116
  as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
83
117
  ):
@@ -93,8 +127,8 @@ def signup(
93
127
  client = get_client(require_auth=False)
94
128
 
95
129
  if not community:
96
- # Only request a fresh OTP when the caller hasn't already supplied one.
97
- # Requesting again would email a NEW code and invalidate the --otp passed in.
130
+ # Only request a code when the caller hasn't already supplied one.
131
+ # (Requesting again re-sends the same code while it is still valid.)
98
132
  if not otp:
99
133
  run(lambda: client.signup_request_otp(admin_email))
100
134
  if not sys.stdin.isatty():
@@ -105,9 +139,7 @@ def signup(
105
139
  f"Re-run this command with --otp <code> to complete signup."
106
140
  )
107
141
  raise typer.Exit(1)
108
- is_local = any(h in client.api_url for h in ("localhost", "127.0.0.1", "0.0.0.0"))
109
- hint = " (localhost test code: 123456)" if is_local else ""
110
- otp = typer.prompt(f"Enter the one-time code emailed to {admin_email}{hint}")
142
+ otp = typer.prompt(f"Enter the one-time code emailed to {admin_email}")
111
143
  data = run(lambda: client.signup_verify_otp(
112
144
  email=admin_email, otp=otp, admin_name=admin_name,
113
145
  admin_password=admin_password, organization_name=name, domain=domain,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chattermate-cli
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: ChatterMate CLI and MCP server — sign up, authenticate, and configure agents, workflows and knowledge from the terminal or an AI agent.
5
5
  Author: ChatterMate
6
6
  License: AGPL-3.0-or-later
@@ -48,6 +48,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
48
48
  # Create an organization + admin (community signup), or log in to an existing one
49
49
  chattermate signup
50
50
  chattermate login --email you@acme.com
51
+ # Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
52
+ chattermate login --token
51
53
 
52
54
  chattermate whoami
53
55
 
@@ -83,6 +85,8 @@ Two credentials are supported:
83
85
  the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
84
86
  - **JWT login** — `chattermate login` stores access + refresh tokens in
85
87
  `~/.chattermate/config.json` (mode `600`) and refreshes automatically.
88
+ `chattermate login --token` stores a PAT there instead, read from a hidden prompt —
89
+ the way to log in for accounts that use Google or Microsoft sign-in.
86
90
 
87
91
  ## MCP server (AI agents)
88
92
 
@@ -25,6 +25,7 @@ chattermate_cli/commands/ticketing.py
25
25
  chattermate_cli/commands/widget.py
26
26
  chattermate_cli/commands/workflow.py
27
27
  tests/test_ai.py
28
+ tests/test_auth.py
28
29
  tests/test_client.py
29
30
  tests/test_customization.py
30
31
  tests/test_help_center.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "chattermate-cli"
7
- version = "0.7.0"
7
+ version = "0.8.0"
8
8
  description = "ChatterMate CLI and MCP server — sign up, authenticate, and configure agents, workflows and knowledge from the terminal or an AI agent."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1,142 @@
1
+ """
2
+ ChatterMate - CLI Auth Command Tests
3
+ Copyright (C) 2024 ChatterMate
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as
7
+ published by the Free Software Foundation, either version 3 of the
8
+ License, or (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Affero General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>
17
+ """
18
+
19
+ import httpx
20
+ import pytest
21
+ from typer.testing import CliRunner
22
+
23
+ from chattermate_cli import config, context
24
+ from chattermate_cli.commands import auth as auth_cmd
25
+ from chattermate_cli.main import app
26
+
27
+ runner = CliRunner()
28
+
29
+ TOKEN = "cmat_live_secret_123"
30
+ USER = {"id": "u1", "email": "sso@acme.com", "organization_id": "o1", "role": {"name": "Admin"}}
31
+
32
+
33
+ @pytest.fixture
34
+ def api(monkeypatch, tmp_path):
35
+ """Isolated config dir plus a fake API that accepts only TOKEN.
36
+
37
+ Commands still build their client through the real get_client, so token
38
+ resolution from config is exercised; only the HTTP transport is faked.
39
+ """
40
+ monkeypatch.setenv(config.ENV_CONFIG_DIR, str(tmp_path))
41
+ monkeypatch.delenv(config.ENV_TOKEN, raising=False)
42
+ monkeypatch.setenv(config.ENV_API_URL, "http://test")
43
+ seen = []
44
+
45
+ def handler(request):
46
+ seen.append(request)
47
+ if request.headers.get("Authorization") != f"Bearer {TOKEN}":
48
+ return httpx.Response(401, json={"detail": "Could not validate credentials"})
49
+ assert (request.method, request.url.path) == ("PATCH", "/api/v1/users/me")
50
+ return httpx.Response(200, json=USER)
51
+
52
+ def mocked_client(require_auth=True):
53
+ client = context.get_client(require_auth)
54
+ client._http = httpx.Client(transport=httpx.MockTransport(handler))
55
+ return client
56
+
57
+ monkeypatch.setattr(auth_cmd, "get_client", mocked_client)
58
+ return seen
59
+
60
+
61
+ def test_login_token_stores_token_and_whoami_uses_it(api):
62
+ result = runner.invoke(app, ["login", "--token"], input=f"{TOKEN}\n")
63
+ assert result.exit_code == 0, result.output
64
+ assert "Logged in as sso@acme.com" in result.output
65
+ # Hidden prompt: the secret is never echoed back.
66
+ assert TOKEN not in result.output
67
+
68
+ cfg = config.load_config()
69
+ assert cfg["access_token"] == TOKEN
70
+ assert cfg["email"] == "sso@acme.com"
71
+ assert cfg["organization_id"] == "o1"
72
+
73
+ result = runner.invoke(app, ["whoami", "--json"])
74
+ assert result.exit_code == 0, result.output
75
+ assert "sso@acme.com" in result.output
76
+ assert api[-1].headers["Authorization"] == f"Bearer {TOKEN}"
77
+
78
+
79
+ def test_login_token_replaces_a_password_session(api):
80
+ config.update_config(access_token="jwt-old", refresh_token="jwt-refresh", email="old@acme.com")
81
+ result = runner.invoke(app, ["login", "--token"], input=f"{TOKEN}\n")
82
+ assert result.exit_code == 0, result.output
83
+ cfg = config.load_config()
84
+ assert cfg["access_token"] == TOKEN
85
+ assert "refresh_token" not in cfg
86
+ assert cfg["email"] == "sso@acme.com"
87
+
88
+
89
+ def test_login_token_rejected_by_api_stores_nothing(api):
90
+ config.update_config(access_token="jwt-old")
91
+ result = runner.invoke(app, ["login", "--token"], input="cmat_revoked\n")
92
+ assert result.exit_code == 1
93
+ assert "Could not validate credentials" in result.output
94
+ assert config.load_config()["access_token"] == "jwt-old"
95
+
96
+
97
+ def test_login_token_refuses_something_that_is_not_a_token(api):
98
+ result = runner.invoke(app, ["login", "--token"], input="hunter2\n")
99
+ assert result.exit_code == 1
100
+ assert "cmat_" in result.output
101
+ assert api == [] # never sent anywhere
102
+ assert config.load_config() == {}
103
+
104
+
105
+ def test_login_token_takes_no_value_on_the_command_line(api):
106
+ # --token is a flag; a secret passed after it is an unexpected argument.
107
+ result = runner.invoke(app, ["login", "--token", TOKEN])
108
+ assert result.exit_code != 0
109
+ assert config.load_config() == {}
110
+
111
+
112
+ def test_login_token_refuses_email_or_password_alongside(api):
113
+ result = runner.invoke(app, ["login", "--token", "--email", "a@acme.com"], input=f"{TOKEN}\n")
114
+ assert result.exit_code == 1
115
+ assert "can't be combined" in result.output
116
+ assert api == []
117
+ assert config.load_config() == {}
118
+
119
+
120
+ def test_password_login_still_prompts(monkeypatch, tmp_path):
121
+ monkeypatch.setenv(config.ENV_CONFIG_DIR, str(tmp_path))
122
+ monkeypatch.setenv(config.ENV_API_URL, "http://test")
123
+
124
+ def handler(request):
125
+ assert request.url.path == "/api/v1/users/login"
126
+ assert b"username=admin%40acme.com" in request.content
127
+ assert b"password=pw" in request.content
128
+ return httpx.Response(200, json={
129
+ "access_token": "jwt-access", "refresh_token": "jwt-refresh",
130
+ "user": {"id": "u1", "email": "admin@acme.com", "organization_id": "o1"},
131
+ })
132
+
133
+ def mocked_client(require_auth=True):
134
+ client = context.get_client(require_auth)
135
+ client._http = httpx.Client(transport=httpx.MockTransport(handler))
136
+ return client
137
+
138
+ monkeypatch.setattr(auth_cmd, "get_client", mocked_client)
139
+ result = runner.invoke(app, ["login"], input="admin@acme.com\npw\n")
140
+ assert result.exit_code == 0, result.output
141
+ assert "Logged in as admin@acme.com" in result.output
142
+ assert config.load_config()["refresh_token"] == "jwt-refresh"
File without changes