codex-usage-tracking 0.3.0__py3-none-any.whl

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 (50) hide show
  1. codex_usage_tracker/__init__.py +7 -0
  2. codex_usage_tracker/__main__.py +6 -0
  3. codex_usage_tracker/allowance.py +759 -0
  4. codex_usage_tracker/api_payloads.py +90 -0
  5. codex_usage_tracker/cli.py +1326 -0
  6. codex_usage_tracker/context.py +410 -0
  7. codex_usage_tracker/costing.py +176 -0
  8. codex_usage_tracker/dashboard.py +389 -0
  9. codex_usage_tracker/diagnostics.py +624 -0
  10. codex_usage_tracker/formatting.py +225 -0
  11. codex_usage_tracker/json_contracts.py +350 -0
  12. codex_usage_tracker/mcp_server.py +371 -0
  13. codex_usage_tracker/models.py +92 -0
  14. codex_usage_tracker/parser.py +491 -0
  15. codex_usage_tracker/paths.py +18 -0
  16. codex_usage_tracker/plugin_data/__init__.py +1 -0
  17. codex_usage_tracker/plugin_data/assets/icon.svg +8 -0
  18. codex_usage_tracker/plugin_data/dashboard/dashboard.css +954 -0
  19. codex_usage_tracker/plugin_data/dashboard/dashboard.js +1833 -0
  20. codex_usage_tracker/plugin_data/dashboard/dashboard_data.js +155 -0
  21. codex_usage_tracker/plugin_data/dashboard/dashboard_format.js +132 -0
  22. codex_usage_tracker/plugin_data/dashboard/dashboard_state.js +157 -0
  23. codex_usage_tracker/plugin_data/dashboard/dashboard_template.html +141 -0
  24. codex_usage_tracker/plugin_data/docs/assets/dashboard-calls.png +0 -0
  25. codex_usage_tracker/plugin_data/docs/assets/dashboard-details.png +0 -0
  26. codex_usage_tracker/plugin_data/docs/assets/dashboard-insights.png +0 -0
  27. codex_usage_tracker/plugin_data/docs/assets/dashboard-threads.png +0 -0
  28. codex_usage_tracker/plugin_data/docs/dashboard-guide.html +136 -0
  29. codex_usage_tracker/plugin_data/rate_cards/codex-credit-rates.json +69 -0
  30. codex_usage_tracker/plugin_data/skills/codex-usage-api/SKILL.md +62 -0
  31. codex_usage_tracker/plugin_data/skills/codex-usage-tracker/SKILL.md +47 -0
  32. codex_usage_tracker/plugin_installer.py +312 -0
  33. codex_usage_tracker/pricing.py +57 -0
  34. codex_usage_tracker/pricing_config.py +223 -0
  35. codex_usage_tracker/pricing_estimates.py +44 -0
  36. codex_usage_tracker/pricing_openai.py +253 -0
  37. codex_usage_tracker/projects.py +347 -0
  38. codex_usage_tracker/recommendations.py +270 -0
  39. codex_usage_tracker/reports.py +637 -0
  40. codex_usage_tracker/schema.py +71 -0
  41. codex_usage_tracker/server.py +400 -0
  42. codex_usage_tracker/store.py +666 -0
  43. codex_usage_tracker/support.py +147 -0
  44. codex_usage_tracker/threads.py +183 -0
  45. codex_usage_tracking-0.3.0.dist-info/METADATA +278 -0
  46. codex_usage_tracking-0.3.0.dist-info/RECORD +50 -0
  47. codex_usage_tracking-0.3.0.dist-info/WHEEL +5 -0
  48. codex_usage_tracking-0.3.0.dist-info/entry_points.txt +2 -0
  49. codex_usage_tracking-0.3.0.dist-info/licenses/LICENSE +21 -0
  50. codex_usage_tracking-0.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,90 @@
1
+ """Stable JSON payload builders shared by CLI and MCP surfaces."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+
9
+ def error_code(exc: BaseException) -> str:
10
+ """Return a stable CLI error code for a user-facing exception."""
11
+
12
+ if isinstance(exc, ValueError):
13
+ return "invalid_value"
14
+ if isinstance(exc, FileExistsError):
15
+ return "file_exists"
16
+ if isinstance(exc, FileNotFoundError):
17
+ return "file_not_found"
18
+ if isinstance(exc, PermissionError):
19
+ return "permission_denied"
20
+ if isinstance(exc, RuntimeError):
21
+ return "runtime_error"
22
+ if isinstance(exc, OSError):
23
+ return "os_error"
24
+ return "error"
25
+
26
+
27
+ def path_payload(path: Path) -> str:
28
+ """Return a user-facing path string with home expansion applied."""
29
+
30
+ return str(path.expanduser())
31
+
32
+
33
+ def refresh_result_payload(result: Any, *, schema: str) -> dict[str, Any]:
34
+ """Return the stable JSON shape for refresh-like operations."""
35
+
36
+ return {
37
+ "schema": schema,
38
+ "scanned_files": result.scanned_files,
39
+ "parsed_events": result.parsed_events,
40
+ "skipped_events": result.skipped_events,
41
+ "inserted_or_updated_events": result.inserted_or_updated_events,
42
+ "db_path": result.db_path,
43
+ "parser_diagnostics": result.parser_diagnostics,
44
+ }
45
+
46
+
47
+ def plugin_install_payload(result: Any, *, schema: str) -> dict[str, Any]:
48
+ """Return the stable JSON shape for install or upgrade plugin operations."""
49
+
50
+ return {
51
+ "schema": schema,
52
+ "plugin_dir": path_payload(result.plugin_dir),
53
+ "marketplace_path": path_payload(result.marketplace_path),
54
+ "python_executable": path_payload(result.python_executable),
55
+ "replaced_existing": result.replaced_existing,
56
+ "restart_required": True,
57
+ }
58
+
59
+
60
+ def plugin_uninstall_payload(result: Any) -> dict[str, Any]:
61
+ """Return the stable JSON shape for plugin uninstall operations."""
62
+
63
+ return {
64
+ "schema": "codex-usage-tracker-plugin-uninstall-v1",
65
+ "plugin_dir": path_payload(result.plugin_dir),
66
+ "marketplace_path": path_payload(result.marketplace_path),
67
+ "removed_plugin_path": result.removed_plugin_path,
68
+ "removed_marketplace_entry": result.removed_marketplace_entry,
69
+ "restart_required": True,
70
+ }
71
+
72
+
73
+ def session_payload(
74
+ rows: list[dict[str, Any]],
75
+ *,
76
+ requested_session_id: str | None,
77
+ limit: int,
78
+ privacy_mode: str = "normal",
79
+ ) -> dict[str, Any]:
80
+ """Return the stable JSON shape for session usage rows."""
81
+
82
+ return {
83
+ "schema": "codex-usage-tracker-session-v1",
84
+ "requested_session_id": requested_session_id,
85
+ "resolved_session_id": rows[0].get("session_id") if rows else requested_session_id,
86
+ "limit": limit,
87
+ "privacy_mode": privacy_mode,
88
+ "row_count": len(rows),
89
+ "rows": rows,
90
+ }