chattermate-cli 0.6.0__tar.gz → 0.7.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 (37) hide show
  1. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/PKG-INFO +9 -1
  2. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/README.md +8 -0
  3. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/__init__.py +1 -1
  4. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/client.py +35 -0
  5. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/customization.py +6 -5
  6. chattermate_cli-0.7.0/chattermate_cli/commands/ticketing.py +396 -0
  7. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/main.py +2 -0
  8. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/PKG-INFO +9 -1
  9. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/SOURCES.txt +2 -0
  10. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/pyproject.toml +1 -1
  11. chattermate_cli-0.7.0/tests/test_ticketing.py +164 -0
  12. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/LICENSE +0 -0
  13. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/__init__.py +0 -0
  14. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/agent.py +0 -0
  15. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/ai.py +0 -0
  16. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/auth.py +0 -0
  17. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/help_center.py +0 -0
  18. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/knowledge.py +0 -0
  19. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/lead_capture.py +0 -0
  20. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/widget.py +0 -0
  21. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/commands/workflow.py +0 -0
  22. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/config.py +0 -0
  23. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/context.py +0 -0
  24. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli/mcp_server.py +0 -0
  25. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/dependency_links.txt +0 -0
  26. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/entry_points.txt +0 -0
  27. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/requires.txt +0 -0
  28. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/chattermate_cli.egg-info/top_level.txt +0 -0
  29. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/setup.cfg +0 -0
  30. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_ai.py +0 -0
  31. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_client.py +0 -0
  32. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_customization.py +0 -0
  33. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_help_center.py +0 -0
  34. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_knowledge.py +0 -0
  35. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_lead_capture.py +0 -0
  36. {chattermate_cli-0.6.0 → chattermate_cli-0.7.0}/tests/test_mcp.py +0 -0
  37. {chattermate_cli-0.6.0 → chattermate_cli-0.7.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.6.0
3
+ Version: 0.7.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
@@ -63,6 +63,14 @@ chattermate workflow get <agent-id>
63
63
  chattermate workflow create --agent-id <agent-id> --name "Onboarding"
64
64
  chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
65
65
  chattermate knowledge status <queue-id>
66
+
67
+ # Inspect AI tickets and drive investigations
68
+ chattermate ticketing list --status open --priority urgent
69
+ chattermate ticketing show TKT-4
70
+ chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
71
+ chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
72
+ chattermate ticketing rca TKT-4 # the root-cause document
73
+ chattermate ticketing settings show
66
74
  ```
67
75
 
68
76
  Every command accepts `--json` for machine-readable output.
@@ -45,6 +45,14 @@ chattermate workflow get <agent-id>
45
45
  chattermate workflow create --agent-id <agent-id> --name "Onboarding"
46
46
  chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
47
47
  chattermate knowledge status <queue-id>
48
+
49
+ # Inspect AI tickets and drive investigations
50
+ chattermate ticketing list --status open --priority urgent
51
+ chattermate ticketing show TKT-4
52
+ chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
53
+ chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
54
+ chattermate ticketing rca TKT-4 # the root-cause document
55
+ chattermate ticketing settings show
48
56
  ```
49
57
 
50
58
  Every command accepts `--json` for machine-readable output.
@@ -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.6.0"
19
+ __version__ = "0.7.0"
@@ -404,3 +404,38 @@ class Client:
404
404
 
405
405
  def help_center_job_by_id(self, job_id: int) -> Any:
406
406
  return self.request("GET", f"/help-center/jobs/{job_id}")
407
+
408
+ # ---- AI ticketing ----
409
+ def list_tickets(self, params: Optional[Dict[str, Any]] = None) -> Any:
410
+ return self.request("GET", "/tickets", params=params)
411
+
412
+ def ticket_stats(self) -> Any:
413
+ return self.request("GET", "/tickets/stats")
414
+
415
+ def get_ticket(self, ticket_id: str) -> Any:
416
+ return self.request("GET", f"/tickets/{ticket_id}")
417
+
418
+ def comment_ticket(self, ticket_id: str, body: str, is_internal: bool = True) -> Any:
419
+ return self.request(
420
+ "POST",
421
+ f"/tickets/{ticket_id}/comments",
422
+ json={"body": body, "is_internal": is_internal},
423
+ )
424
+
425
+ def investigate_ticket(
426
+ self, ticket_id: str, run_type: str = "investigation", context_note: Optional[str] = None
427
+ ) -> Any:
428
+ payload: Dict[str, Any] = {"run_type": run_type}
429
+ if context_note:
430
+ payload["context_note"] = context_note
431
+ return self.request("POST", f"/tickets/{ticket_id}/investigate", json=payload)
432
+
433
+ def ticket_investigation(self, ticket_id: str, run_id: Optional[str] = None) -> Any:
434
+ params = {"run_id": run_id} if run_id else None
435
+ return self.request("GET", f"/tickets/{ticket_id}/investigation", params=params)
436
+
437
+ def get_ticket_settings(self) -> Any:
438
+ return self.request("GET", "/tickets/settings")
439
+
440
+ def update_ticket_settings(self, payload: Dict[str, Any]) -> Any:
441
+ return self.request("PUT", "/tickets/settings", json=payload)
@@ -90,14 +90,15 @@ def set_customization(
90
90
  None, "--position", help=f"Widget position. One of: {', '.join(WIDGET_POSITIONS)}."),
91
91
  font: Optional[str] = typer.Option(None, "--font", help="Font family."),
92
92
  custom_css: Optional[str] = typer.Option(None, "--custom-css", help="Custom CSS."),
93
- # Welcome / messaging
94
- welcome_title: Optional[str] = typer.Option(None, "--welcome-title"),
95
- welcome_subtitle: Optional[str] = typer.Option(None, "--welcome-subtitle"),
96
- welcome_message: Optional[str] = typer.Option(None, "--welcome-message"),
93
+ # Welcome / messaging (max lengths enforced by the API)
94
+ welcome_title: Optional[str] = typer.Option(None, "--welcome-title", help="Welcome title (max 100 chars)."),
95
+ welcome_subtitle: Optional[str] = typer.Option(None, "--welcome-subtitle", help="Welcome subtitle (max 250 chars)."),
96
+ welcome_message: Optional[str] = typer.Option(None, "--welcome-message", help="Welcome message (max 500 chars)."),
97
97
  quick_action: List[str] = typer.Option(
98
98
  [], "--quick-action", help="Quick-action chip (repeatable; replaces the list)."),
99
99
  initiation_message: List[str] = typer.Option(
100
- [], "--initiation-message", help="Proactive initiation message (repeatable; replaces the list)."),
100
+ [], "--initiation-message",
101
+ help="Proactive launcher nudge, max 100 chars (repeatable; replaces the list)."),
101
102
  # Toggles
102
103
  show_citations: Optional[bool] = typer.Option(
103
104
  None, "--show-citations/--no-show-citations", help="Show knowledge-base citations."),
@@ -0,0 +1,396 @@
1
+ """
2
+ ChatterMate - CLI AI Ticketing Commands
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
+ Inspect AI tickets and drive investigations from the terminal: list and read
20
+ tickets, watch the glass-box investigation, read the RCA, and kick off a run.
21
+
22
+ Customer-facing and destructive actions (resolving, approving an AI proposal,
23
+ messaging a customer, connector credentials) are deliberately NOT exposed here
24
+ — those belong in the dashboard where there's an audit trail and a human
25
+ looking at what's about to be sent.
26
+ """
27
+
28
+ import uuid
29
+ from typing import Any, Dict, Optional
30
+
31
+ import typer
32
+ from rich.table import Table
33
+
34
+ from ..context import console, get_client, output, print_error, run
35
+
36
+ ticketing_app = typer.Typer(
37
+ no_args_is_help=True,
38
+ help="Inspect AI tickets, investigations and RCAs; trigger an investigation.",
39
+ )
40
+ settings_app = typer.Typer(no_args_is_help=True, help="Read and update ticketing settings.")
41
+ ticketing_app.add_typer(settings_app, name="settings")
42
+
43
+ STATUSES = [
44
+ "open", "triaging", "investigating", "awaiting_approval", "in_progress",
45
+ "resolved_pending_confirmation", "resolved", "closed", "reopened",
46
+ ]
47
+ PRIORITIES = ["urgent", "high", "medium", "low"]
48
+
49
+ # Confidence bar in the glass box, so `show`/`investigation` read like the UI.
50
+ _BAR_WIDTH = 24
51
+ # The list endpoint caps page_size at 100; ask for the most we can so a
52
+ # number lookup isn't defeated by a busy org (see _resolve_ticket_id).
53
+ _LOOKUP_PAGE_SIZE = 100
54
+
55
+
56
+ def _tickets_of(payload: Any) -> list:
57
+ """Rows out of a list response. The API returns {"tickets": [...]}."""
58
+ if isinstance(payload, dict):
59
+ return payload.get("tickets") or []
60
+ return payload or []
61
+
62
+
63
+ def _resolve_ticket_id(client, ref: str) -> str:
64
+ """Accept a TKT-4 / 4 / raw UUID and return the ticket's UUID.
65
+
66
+ The API addresses tickets by UUID, but everyone reads and speaks in
67
+ ticket numbers — so take either. The list endpoint's search matches on
68
+ ticket_number when the term has digits, but it ORs that with a title and
69
+ description LIKE, so a common number can return many rows; we match the
70
+ number exactly and say so honestly when it isn't on the page.
71
+ """
72
+ ref = (ref or "").strip()
73
+ try:
74
+ return str(uuid.UUID(ref)) # already an id
75
+ except (ValueError, AttributeError, TypeError):
76
+ pass
77
+ digits = ref.upper().removeprefix("TKT-").strip()
78
+ if not digits.isdigit():
79
+ print_error(f"'{ref}' is not a ticket number (TKT-4) or a ticket ID.")
80
+ raise typer.Exit(1)
81
+
82
+ data = client.list_tickets({"search": digits, "page_size": _LOOKUP_PAGE_SIZE})
83
+ rows = _tickets_of(data)
84
+ for t in rows:
85
+ if str(t.get("ticket_number")) == digits:
86
+ return t["id"]
87
+ if len(rows) >= _LOOKUP_PAGE_SIZE:
88
+ print_error(
89
+ f"Could not find TKT-{digits} in the first {_LOOKUP_PAGE_SIZE} search "
90
+ "results — pass the ticket ID instead."
91
+ )
92
+ else:
93
+ print_error(f"No ticket found for '{ref}'.")
94
+ raise typer.Exit(1)
95
+
96
+
97
+ def _bar(value: Optional[float]) -> str:
98
+ if value is None:
99
+ return ""
100
+ filled = max(0, min(_BAR_WIDTH, round(float(value) * _BAR_WIDTH)))
101
+ return "█" * filled + "░" * (_BAR_WIDTH - filled)
102
+
103
+
104
+ @ticketing_app.command("list")
105
+ def list_tickets(
106
+ status: Optional[str] = typer.Option(None, "--status", help=f"One of: {', '.join(STATUSES)}."),
107
+ priority: Optional[str] = typer.Option(None, "--priority", help=f"One of: {', '.join(PRIORITIES)}."),
108
+ search: Optional[str] = typer.Option(None, "--search", help="Match title, description or ticket number."),
109
+ limit: int = typer.Option(20, "--limit", help="How many tickets to show."),
110
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
111
+ ):
112
+ """List tickets, newest first."""
113
+ if status and status not in STATUSES:
114
+ print_error(f"Unknown status '{status}'. Expected one of: {', '.join(STATUSES)}")
115
+ raise typer.Exit(1)
116
+ if priority and priority not in PRIORITIES:
117
+ print_error(f"Unknown priority '{priority}'. Expected one of: {', '.join(PRIORITIES)}")
118
+ raise typer.Exit(1)
119
+
120
+ params: Dict[str, Any] = {"page_size": limit}
121
+ if status:
122
+ params["status"] = status
123
+ if priority:
124
+ params["priority"] = priority
125
+ if search:
126
+ params["search"] = search
127
+
128
+ client = get_client()
129
+ data = run(lambda: client.list_tickets(params))
130
+
131
+ def render(payload):
132
+ items = _tickets_of(payload)
133
+ if not items:
134
+ console.print("No tickets found.")
135
+ return
136
+ table = Table(show_header=True, header_style="bold")
137
+ table.add_column("TICKET")
138
+ table.add_column("TITLE")
139
+ table.add_column("STATUS")
140
+ table.add_column("PRIORITY")
141
+ for t in items:
142
+ table.add_row(
143
+ f"TKT-{t.get('ticket_number')}",
144
+ (t.get("title") or "")[:60],
145
+ str(t.get("status") or ""),
146
+ str(t.get("priority") or ""),
147
+ )
148
+ console.print(table)
149
+
150
+ output(data, as_json, render)
151
+
152
+
153
+ @ticketing_app.command("show")
154
+ def show_ticket(
155
+ ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
156
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
157
+ ):
158
+ """Show a ticket: triage, description and recent activity."""
159
+ client = get_client()
160
+ ticket_id = _resolve_ticket_id(client, ticket)
161
+ data = run(lambda: client.get_ticket(ticket_id))
162
+
163
+ def render(payload):
164
+ t = payload.get("ticket") if isinstance(payload, dict) else payload
165
+ if not isinstance(t, dict):
166
+ console.print(str(payload))
167
+ return
168
+ console.print(f"[bold]TKT-{t.get('ticket_number')}[/bold] {t.get('title') or ''}")
169
+ console.print(f" status: {t.get('status')}")
170
+ console.print(f" priority: {t.get('priority')} severity: {t.get('severity') or '-'}")
171
+ if t.get("intent"):
172
+ conf = t.get("triage_confidence")
173
+ conf_txt = f" ({conf})" if conf is not None else ""
174
+ console.print(f" intent: {t.get('intent')}{conf_txt}")
175
+ if t.get("ai_summary"):
176
+ console.print(f"\n [bold]AI summary[/bold]\n {t['ai_summary']}")
177
+ if t.get("description"):
178
+ console.print(f"\n [bold]Description[/bold]\n {t['description']}")
179
+ activities = payload.get("activities") if isinstance(payload, dict) else None
180
+ if activities:
181
+ console.print("\n [bold]Recent activity[/bold]")
182
+ for a in activities[-8:]:
183
+ body = (a.get("body") or "").replace("\n", " ")[:90]
184
+ console.print(f" - [{a.get('activity_type')}] {body}")
185
+
186
+ output(data, as_json, render)
187
+
188
+
189
+ @ticketing_app.command("investigation")
190
+ def show_investigation(
191
+ ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
192
+ run_id: Optional[str] = typer.Option(None, "--run", help="A specific run; defaults to the latest."),
193
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
194
+ ):
195
+ """Show the glass box: hypotheses, verdicts and evidence counts."""
196
+ client = get_client()
197
+ ticket_id = _resolve_ticket_id(client, ticket)
198
+ data = run(lambda: client.ticket_investigation(ticket_id, run_id))
199
+
200
+ def render(payload):
201
+ if not isinstance(payload, dict):
202
+ console.print(str(payload))
203
+ return
204
+ run_info = payload.get("run") or {}
205
+ if not run_info:
206
+ console.print("No investigation has run for this ticket yet.")
207
+ return
208
+ console.print(
209
+ f"[bold]{run_info.get('run_type')}[/bold] · {run_info.get('status')} · "
210
+ f"{run_info.get('llm_calls', 0)} LLM calls · "
211
+ f"{run_info.get('tool_calls_used', 0)}/{run_info.get('max_tool_calls', '-')} tool calls"
212
+ )
213
+ if run_info.get("model_name"):
214
+ console.print(f" model: {run_info['model_name']}")
215
+ if run_info.get("error"):
216
+ console.print(f" [red]error:[/red] {run_info['error']}")
217
+
218
+ for h in payload.get("hypotheses") or []:
219
+ conf = h.get("confidence")
220
+ console.print(
221
+ f"\n H{h.get('idx')} {h.get('title')}\n"
222
+ f" {h.get('status')} {_bar(conf)} {conf if conf is not None else ''}"
223
+ )
224
+ events = payload.get("events") or []
225
+ if events:
226
+ console.print(f"\n {len(events)} evidence event(s) recorded.")
227
+
228
+ output(data, as_json, render)
229
+
230
+
231
+ @ticketing_app.command("rca")
232
+ def show_rca(
233
+ ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
234
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
235
+ ):
236
+ """Print the root-cause analysis document for a ticket."""
237
+ client = get_client()
238
+ ticket_id = _resolve_ticket_id(client, ticket)
239
+ data = run(lambda: client.ticket_investigation(ticket_id))
240
+
241
+ def render(payload):
242
+ rca = (payload or {}).get("rca") if isinstance(payload, dict) else None
243
+ if not rca:
244
+ console.print("No RCA document yet — run an investigation first.")
245
+ return
246
+ version = rca.get("version")
247
+ console.print(f"[bold]Root-cause analysis[/bold] (v{version})\n")
248
+ for key, label in [
249
+ ("summary", "Summary"),
250
+ ("impact", "Impact"),
251
+ ("investigation_log", "Investigation log"),
252
+ ("contributing_factors", "Contributing factors"),
253
+ ("conclusion", "Conclusion"),
254
+ ("remediation", "Remediation"),
255
+ ("prevention", "Prevention"),
256
+ ("customer_summary", "Customer summary"),
257
+ ]:
258
+ value = rca.get(key)
259
+ if not value:
260
+ continue
261
+ if isinstance(value, list):
262
+ value = "\n ".join(f"- {v}" for v in value)
263
+ console.print(f"[bold]{label}[/bold]\n {value}\n")
264
+
265
+ output(data, as_json, render)
266
+
267
+
268
+ @ticketing_app.command("investigate")
269
+ def investigate(
270
+ ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
271
+ triage_only: bool = typer.Option(False, "--triage-only", help="Run triage instead of a full investigation."),
272
+ note: Optional[str] = typer.Option(None, "--note", help="Extra context to steer the run."),
273
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
274
+ ):
275
+ """Queue an AI run for a ticket. The worker picks it up within ~15s."""
276
+ client = get_client()
277
+ ticket_id = _resolve_ticket_id(client, ticket)
278
+ run_type = "triage" if triage_only else "investigation"
279
+ data = run(lambda: client.investigate_ticket(ticket_id, run_type=run_type, context_note=note))
280
+
281
+ def render(payload):
282
+ console.print(
283
+ f"Queued {run_type} run [bold]{(payload or {}).get('id', '')}[/bold] — "
284
+ f"follow it with: chattermate ticketing investigation {ticket}"
285
+ )
286
+
287
+ output(data, as_json, render)
288
+
289
+
290
+ @ticketing_app.command("comment")
291
+ def comment(
292
+ ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
293
+ body: str = typer.Argument(..., help="The note text."),
294
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
295
+ ):
296
+ """Add an internal note to a ticket.
297
+
298
+ Internal only, by design — anything the customer would receive goes through
299
+ the dashboard, where a human sees it before it is sent.
300
+ """
301
+ client = get_client()
302
+ ticket_id = _resolve_ticket_id(client, ticket)
303
+ data = run(lambda: client.comment_ticket(ticket_id, body, is_internal=True))
304
+
305
+ def render(_payload):
306
+ console.print(f"Added internal note to {ticket}.")
307
+
308
+ output(data, as_json, render)
309
+
310
+
311
+ @ticketing_app.command("stats")
312
+ def stats(as_json: bool = typer.Option(False, "--json", help="Output raw JSON.")):
313
+ """Workspace counters: open, awaiting approval, SLA breaching, AI-resolved."""
314
+ client = get_client()
315
+ data = run(lambda: client.ticket_stats())
316
+
317
+ def render(payload):
318
+ if not isinstance(payload, dict):
319
+ console.print(str(payload))
320
+ return
321
+ for key, value in payload.items():
322
+ console.print(f" {key.replace('_', ' '):<24} {value}")
323
+
324
+ output(data, as_json, render)
325
+
326
+
327
+ @settings_app.command("show")
328
+ def settings_show(as_json: bool = typer.Option(False, "--json", help="Output raw JSON.")):
329
+ """Show the organization's ticketing settings."""
330
+ client = get_client()
331
+ data = run(lambda: client.get_ticket_settings())
332
+
333
+ def render(cfg):
334
+ if not isinstance(cfg, dict):
335
+ console.print(str(cfg))
336
+ return
337
+ levels = {1: "L1 investigate only", 2: "L2 propose, human approves", 3: "L3 auto-resolve"}
338
+ level = cfg.get("autonomy_level")
339
+ console.print(f" autonomy: {level} — {levels.get(level, '')}")
340
+ console.print(f" auto-investigate: {cfg.get('auto_investigate_on_create')}")
341
+ console.print(f" min confidence (L3): {cfg.get('min_confidence_to_auto_resolve')}")
342
+ console.print(f" confirm timeout: {cfg.get('confirmation_timeout_hours')}h")
343
+ console.print(f" CSAT: {cfg.get('csat_enabled')}")
344
+ console.print(f" max tool calls/run: {cfg.get('max_tool_calls_per_run')}")
345
+ console.print(f" max runs/ticket: {cfg.get('max_runs_per_ticket')}")
346
+ console.print(f" jira escalation: {cfg.get('jira_escalation_enabled')}")
347
+ console.print(f" alert webhook: {cfg.get('alert_webhook_enabled')}")
348
+
349
+ output(data, as_json, render)
350
+
351
+
352
+ @settings_app.command("set")
353
+ def settings_set(
354
+ autonomy: Optional[int] = typer.Option(None, "--autonomy", min=1, max=3, help="1, 2 or 3."),
355
+ auto_investigate: Optional[bool] = typer.Option(
356
+ None, "--auto-investigate/--no-auto-investigate", help="Triage every new ticket automatically."
357
+ ),
358
+ csat: Optional[bool] = typer.Option(None, "--csat/--no-csat", help="Ask for CSAT after resolution."),
359
+ min_confidence: Optional[float] = typer.Option(
360
+ None, "--min-confidence", min=0.0, max=1.0, help="L3 auto-resolve confidence floor."
361
+ ),
362
+ confirm_timeout: Optional[int] = typer.Option(
363
+ None, "--confirm-timeout", help="Hours to wait for a customer reply before closing."
364
+ ),
365
+ max_tool_calls: Optional[int] = typer.Option(None, "--max-tool-calls", help="Tool-call budget per run."),
366
+ max_runs: Optional[int] = typer.Option(None, "--max-runs", help="Investigation runs per ticket."),
367
+ as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
368
+ ):
369
+ """Update ticketing settings. Only the flags you pass are changed."""
370
+ payload: Dict[str, Any] = {}
371
+ if autonomy is not None:
372
+ payload["autonomy_level"] = autonomy
373
+ if auto_investigate is not None:
374
+ payload["auto_investigate_on_create"] = auto_investigate
375
+ if csat is not None:
376
+ payload["csat_enabled"] = csat
377
+ if min_confidence is not None:
378
+ payload["min_confidence_to_auto_resolve"] = min_confidence
379
+ if confirm_timeout is not None:
380
+ payload["confirmation_timeout_hours"] = confirm_timeout
381
+ if max_tool_calls is not None:
382
+ payload["max_tool_calls_per_run"] = max_tool_calls
383
+ if max_runs is not None:
384
+ payload["max_runs_per_ticket"] = max_runs
385
+
386
+ if not payload:
387
+ print_error("Nothing to update — pass at least one option (see --help).")
388
+ raise typer.Exit(1)
389
+
390
+ client = get_client()
391
+ data = run(lambda: client.update_ticket_settings(payload))
392
+
393
+ def render(_cfg):
394
+ console.print("Ticketing settings updated: " + ", ".join(sorted(payload)))
395
+
396
+ output(data, as_json, render)
@@ -28,6 +28,7 @@ from .commands.customization import customization_app
28
28
  from .commands.help_center import help_center_app
29
29
  from .commands.knowledge import knowledge_app
30
30
  from .commands.lead_capture import lead_app
31
+ from .commands.ticketing import ticketing_app
31
32
  from .commands.widget import widget_app
32
33
  from .commands.workflow import workflow_app
33
34
 
@@ -74,6 +75,7 @@ app.add_typer(knowledge_app, name="knowledge")
74
75
  app.add_typer(lead_app, name="lead-capture")
75
76
  app.add_typer(customization_app, name="customization")
76
77
  app.add_typer(help_center_app, name="help-center")
78
+ app.add_typer(ticketing_app, name="ticketing")
77
79
 
78
80
 
79
81
  def main():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chattermate-cli
3
- Version: 0.6.0
3
+ Version: 0.7.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
@@ -63,6 +63,14 @@ chattermate workflow get <agent-id>
63
63
  chattermate workflow create --agent-id <agent-id> --name "Onboarding"
64
64
  chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
65
65
  chattermate knowledge status <queue-id>
66
+
67
+ # Inspect AI tickets and drive investigations
68
+ chattermate ticketing list --status open --priority urgent
69
+ chattermate ticketing show TKT-4
70
+ chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
71
+ chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
72
+ chattermate ticketing rca TKT-4 # the root-cause document
73
+ chattermate ticketing settings show
66
74
  ```
67
75
 
68
76
  Every command accepts `--json` for machine-readable output.
@@ -21,6 +21,7 @@ chattermate_cli/commands/customization.py
21
21
  chattermate_cli/commands/help_center.py
22
22
  chattermate_cli/commands/knowledge.py
23
23
  chattermate_cli/commands/lead_capture.py
24
+ chattermate_cli/commands/ticketing.py
24
25
  chattermate_cli/commands/widget.py
25
26
  chattermate_cli/commands/workflow.py
26
27
  tests/test_ai.py
@@ -30,4 +31,5 @@ tests/test_help_center.py
30
31
  tests/test_knowledge.py
31
32
  tests/test_lead_capture.py
32
33
  tests/test_mcp.py
34
+ tests/test_ticketing.py
33
35
  tests/test_widget.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "chattermate-cli"
7
- version = "0.6.0"
7
+ version = "0.7.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,164 @@
1
+ """
2
+ ChatterMate - CLI AI Ticketing 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
+
11
+ import httpx
12
+ import pytest
13
+ import typer
14
+
15
+ from chattermate_cli.client import Client
16
+ from chattermate_cli.commands.ticketing import _resolve_ticket_id
17
+
18
+
19
+ def make_client(handler, token="cmat_x"):
20
+ client = Client(api_url="http://test", token=token)
21
+ client._http = httpx.Client(transport=httpx.MockTransport(handler))
22
+ return client
23
+
24
+
25
+ # ---------- client paths ----------
26
+
27
+ def test_list_tickets_path_and_params():
28
+ seen = {}
29
+
30
+ def handler(request):
31
+ seen["method"] = request.method
32
+ seen["path"] = request.url.path
33
+ seen["query"] = dict(request.url.params)
34
+ return httpx.Response(200, json={"tickets": [], "pagination": {}})
35
+
36
+ make_client(handler).list_tickets({"status": "open", "page_size": 5})
37
+
38
+ assert seen["method"] == "GET"
39
+ assert seen["path"] == "/api/v1/tickets"
40
+ assert seen["query"]["status"] == "open"
41
+
42
+
43
+ def test_investigate_posts_run_type_and_note():
44
+ seen = {}
45
+
46
+ def handler(request):
47
+ import json as _json
48
+ seen["method"] = request.method
49
+ seen["path"] = request.url.path
50
+ seen["body"] = _json.loads(request.content)
51
+ return httpx.Response(201, json={"id": "run-1"})
52
+
53
+ make_client(handler).investigate_ticket("t-1", run_type="triage", context_note="check gateway")
54
+
55
+ assert seen["method"] == "POST"
56
+ assert seen["path"] == "/api/v1/tickets/t-1/investigate"
57
+ assert seen["body"] == {"run_type": "triage", "context_note": "check gateway"}
58
+
59
+
60
+ def test_comment_defaults_to_internal():
61
+ seen = {}
62
+
63
+ def handler(request):
64
+ import json as _json
65
+ seen["body"] = _json.loads(request.content)
66
+ return httpx.Response(201, json={})
67
+
68
+ make_client(handler).comment_ticket("t-1", "looked at logs")
69
+
70
+ assert seen["body"]["is_internal"] is True
71
+
72
+
73
+ def test_investigation_passes_run_id():
74
+ seen = {}
75
+
76
+ def handler(request):
77
+ seen["query"] = dict(request.url.params)
78
+ return httpx.Response(200, json={"run": {}})
79
+
80
+ make_client(handler).ticket_investigation("t-1", run_id="r-9")
81
+
82
+ assert seen["query"]["run_id"] == "r-9"
83
+
84
+
85
+ def test_update_settings_puts_payload():
86
+ seen = {}
87
+
88
+ def handler(request):
89
+ import json as _json
90
+ seen["method"] = request.method
91
+ seen["path"] = request.url.path
92
+ seen["body"] = _json.loads(request.content)
93
+ return httpx.Response(200, json={})
94
+
95
+ make_client(handler).update_ticket_settings({"autonomy_level": 2})
96
+
97
+ assert seen["method"] == "PUT"
98
+ assert seen["path"] == "/api/v1/tickets/settings"
99
+ assert seen["body"] == {"autonomy_level": 2}
100
+
101
+
102
+ # ---------- ticket reference resolution ----------
103
+ # Everyone reads "TKT-4"; the API wants the UUID. The CLI has to bridge that.
104
+
105
+ UUID_ONE = "c6575003-8472-4bba-88d4-6a414c392b1f"
106
+
107
+
108
+ def _search_client(items):
109
+ def handler(request):
110
+ return httpx.Response(200, json={"tickets": items, "pagination": {}})
111
+ return make_client(handler)
112
+
113
+
114
+ def test_resolves_ticket_number_to_uuid():
115
+ client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
116
+ assert _resolve_ticket_id(client, "TKT-4") == UUID_ONE
117
+
118
+
119
+ def test_resolves_bare_number():
120
+ client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
121
+ assert _resolve_ticket_id(client, "4") == UUID_ONE
122
+
123
+
124
+ def test_ignores_near_miss_numbers():
125
+ # search matches on digits, so 4 must not resolve to 44
126
+ client = _search_client([{"id": "other", "ticket_number": 44}])
127
+ with pytest.raises(typer.Exit):
128
+ _resolve_ticket_id(client, "TKT-4")
129
+
130
+
131
+ def test_uuid_passes_through_without_a_lookup():
132
+ def handler(request): # pragma: no cover - must never be called
133
+ raise AssertionError("should not hit the API for a UUID")
134
+
135
+ assert _resolve_ticket_id(make_client(handler), UUID_ONE) == UUID_ONE
136
+
137
+
138
+ def test_unknown_reference_exits():
139
+ client = _search_client([])
140
+ with pytest.raises(typer.Exit):
141
+ _resolve_ticket_id(client, "TKT-999")
142
+
143
+
144
+ def test_reads_the_real_tickets_key_not_items():
145
+ # Regression: the API returns {"tickets": [...]}; an "items" assumption
146
+ # silently resolved nothing and made every lookup fail.
147
+ client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
148
+ assert _resolve_ticket_id(client, "TKT-4") == UUID_ONE
149
+
150
+
151
+ def test_non_numeric_reference_exits_without_calling_the_api():
152
+ def handler(request): # pragma: no cover - must never be called
153
+ raise AssertionError("should not hit the API for a junk ref")
154
+
155
+ with pytest.raises(typer.Exit):
156
+ _resolve_ticket_id(make_client(handler), "not-a-ticket")
157
+
158
+
159
+ def test_full_page_of_misses_reports_truncation():
160
+ # A common digit can fill the page via the title/description LIKE, so the
161
+ # number may genuinely not be on it — say so instead of "not found".
162
+ rows = [{"id": f"id-{i}", "ticket_number": 400 + i} for i in range(100)]
163
+ with pytest.raises(typer.Exit):
164
+ _resolve_ticket_id(_search_client(rows), "TKT-4")
File without changes