bannin 0.1.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 (77) hide show
  1. bannin-0.1.0/LICENSE +21 -0
  2. bannin-0.1.0/PKG-INFO +238 -0
  3. bannin-0.1.0/README.md +204 -0
  4. bannin-0.1.0/bannin/__init__.py +139 -0
  5. bannin-0.1.0/bannin/analytics/__init__.py +3 -0
  6. bannin-0.1.0/bannin/analytics/api.py +112 -0
  7. bannin-0.1.0/bannin/analytics/dashboard.html +485 -0
  8. bannin-0.1.0/bannin/analytics/pipeline.py +160 -0
  9. bannin-0.1.0/bannin/analytics/store.py +363 -0
  10. bannin-0.1.0/bannin/api.py +482 -0
  11. bannin-0.1.0/bannin/cli.py +222 -0
  12. bannin-0.1.0/bannin/config/__init__.py +1 -0
  13. bannin-0.1.0/bannin/config/defaults.json +454 -0
  14. bannin-0.1.0/bannin/config/loader.py +170 -0
  15. bannin-0.1.0/bannin/core/__init__.py +1 -0
  16. bannin-0.1.0/bannin/core/collector.py +72 -0
  17. bannin-0.1.0/bannin/core/gpu.py +65 -0
  18. bannin-0.1.0/bannin/core/process.py +379 -0
  19. bannin-0.1.0/bannin/core/process_names.py +246 -0
  20. bannin-0.1.0/bannin/dashboard.html +1798 -0
  21. bannin-0.1.0/bannin/intelligence/__init__.py +12 -0
  22. bannin-0.1.0/bannin/intelligence/alerts.py +439 -0
  23. bannin-0.1.0/bannin/intelligence/chat.py +746 -0
  24. bannin-0.1.0/bannin/intelligence/history.py +249 -0
  25. bannin-0.1.0/bannin/intelligence/oom.py +238 -0
  26. bannin-0.1.0/bannin/intelligence/progress.py +476 -0
  27. bannin-0.1.0/bannin/intelligence/recommendations.py +245 -0
  28. bannin-0.1.0/bannin/intelligence/summary.py +175 -0
  29. bannin-0.1.0/bannin/intelligence/training.py +244 -0
  30. bannin-0.1.0/bannin/llm/__init__.py +6 -0
  31. bannin-0.1.0/bannin/llm/aggregator.py +226 -0
  32. bannin-0.1.0/bannin/llm/claude_session.py +403 -0
  33. bannin-0.1.0/bannin/llm/connections.py +176 -0
  34. bannin-0.1.0/bannin/llm/health.py +512 -0
  35. bannin-0.1.0/bannin/llm/ollama.py +288 -0
  36. bannin-0.1.0/bannin/llm/pricing.py +113 -0
  37. bannin-0.1.0/bannin/llm/tracker.py +399 -0
  38. bannin-0.1.0/bannin/llm/wrapper.py +516 -0
  39. bannin-0.1.0/bannin/log.py +65 -0
  40. bannin-0.1.0/bannin/mcp/__init__.py +7 -0
  41. bannin-0.1.0/bannin/mcp/__main__.py +25 -0
  42. bannin-0.1.0/bannin/mcp/server.py +424 -0
  43. bannin-0.1.0/bannin/mcp/session.py +449 -0
  44. bannin-0.1.0/bannin/platforms/__init__.py +1 -0
  45. bannin-0.1.0/bannin/platforms/colab.py +299 -0
  46. bannin-0.1.0/bannin/platforms/detector.py +50 -0
  47. bannin-0.1.0/bannin/platforms/kaggle.py +442 -0
  48. bannin-0.1.0/bannin/relay.py +386 -0
  49. bannin-0.1.0/bannin/routes/__init__.py +58 -0
  50. bannin-0.1.0/bannin/routes/actions.py +410 -0
  51. bannin-0.1.0/bannin/routes/analytics.py +56 -0
  52. bannin-0.1.0/bannin/routes/intelligence.py +138 -0
  53. bannin-0.1.0/bannin/routes/llm.py +54 -0
  54. bannin-0.1.0/bannin/routes/mcp.py +63 -0
  55. bannin-0.1.0/bannin/state.py +63 -0
  56. bannin-0.1.0/bannin.egg-info/PKG-INFO +238 -0
  57. bannin-0.1.0/bannin.egg-info/SOURCES.txt +75 -0
  58. bannin-0.1.0/bannin.egg-info/dependency_links.txt +1 -0
  59. bannin-0.1.0/bannin.egg-info/entry_points.txt +3 -0
  60. bannin-0.1.0/bannin.egg-info/requires.txt +14 -0
  61. bannin-0.1.0/bannin.egg-info/top_level.txt +1 -0
  62. bannin-0.1.0/pyproject.toml +52 -0
  63. bannin-0.1.0/setup.cfg +4 -0
  64. bannin-0.1.0/setup.py +3 -0
  65. bannin-0.1.0/tests/test_actions.py +95 -0
  66. bannin-0.1.0/tests/test_aggregator.py +303 -0
  67. bannin-0.1.0/tests/test_alert_engine.py +466 -0
  68. bannin-0.1.0/tests/test_api_endpoints.py +360 -0
  69. bannin-0.1.0/tests/test_chat_handlers.py +546 -0
  70. bannin-0.1.0/tests/test_chat_intents.py +204 -0
  71. bannin-0.1.0/tests/test_health_scoring.py +360 -0
  72. bannin-0.1.0/tests/test_llm_wrapper.py +351 -0
  73. bannin-0.1.0/tests/test_oom_prediction.py +304 -0
  74. bannin-0.1.0/tests/test_recommendations.py +395 -0
  75. bannin-0.1.0/tests/test_token_estimation.py +350 -0
  76. bannin-0.1.0/tests/test_token_validation.py +316 -0
  77. bannin-0.1.0/tests/test_training_detection.py +201 -0
bannin-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bannin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
bannin-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,238 @@
1
+ Metadata-Version: 2.4
2
+ Name: bannin
3
+ Version: 0.1.0
4
+ Summary: Universal monitoring platform — watch your machines, LLMs, notebooks, and coding tools from your phone.
5
+ Author: Bannin Team
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Lakshman-P4/Bannin.dev
8
+ Project-URL: Issues, https://github.com/Lakshman-P4/Bannin.dev/issues
9
+ Keywords: monitoring,system-metrics,llm,gpu,colab,kaggle,machine-learning
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: System :: Monitoring
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: psutil>=5.9.0
23
+ Requires-Dist: fastapi>=0.104.0
24
+ Requires-Dist: uvicorn>=0.24.0
25
+ Requires-Dist: websockets>=12.0
26
+ Provides-Extra: gpu
27
+ Requires-Dist: pynvml>=11.5.0; extra == "gpu"
28
+ Provides-Extra: mcp
29
+ Requires-Dist: mcp>=1.2.0; extra == "mcp"
30
+ Provides-Extra: all
31
+ Requires-Dist: pynvml>=11.5.0; extra == "all"
32
+ Requires-Dist: mcp>=1.2.0; extra == "all"
33
+ Dynamic: license-file
34
+
35
+ # Bannin
36
+
37
+ **番人** (Japanese for "watchman") — a universal monitoring agent for your machine, your LLMs, and your cloud notebooks.
38
+
39
+ *You hit run. You walk away. Then what?*
40
+
41
+ ---
42
+
43
+ ## What It Does
44
+
45
+ Bannin runs on your machine (or inside a cloud notebook) and monitors everything: CPU, RAM, GPU, disk, running processes, LLM conversation health, API usage, and cloud session health. It predicts out-of-memory crashes before they happen, scores your AI conversation quality, fires smart alerts, and gives you plain-English summaries of how your system is doing.
46
+
47
+ It also works as an **MCP server** — meaning AI coding tools (Claude Code, Cursor, Windsurf) can query your system health through natural conversation.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install bannin
53
+ ```
54
+
55
+ With GPU monitoring and MCP server support:
56
+
57
+ ```bash
58
+ pip install "bannin[all]"
59
+ ```
60
+
61
+ ## Quick Start
62
+
63
+ **Start the agent:**
64
+
65
+ ```bash
66
+ bannin start
67
+ ```
68
+
69
+ **Open the dashboard:**
70
+
71
+ Visit [localhost:8420](http://localhost:8420) in your browser.
72
+
73
+ **Use with Claude Code (MCP):**
74
+
75
+ Add to your `.mcp.json`:
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "bannin": {
81
+ "command": "python",
82
+ "args": ["-m", "bannin.mcp"]
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ Then ask Claude things like:
89
+ - "How's my system doing?"
90
+ - "What processes are using the most memory?"
91
+ - "Am I going to run out of RAM?"
92
+ - "How healthy is this conversation?"
93
+
94
+ ## Features
95
+
96
+ ### System Monitoring
97
+ - CPU, RAM, disk, network -- real-time with 30-minute history
98
+ - GPU monitoring (NVIDIA via pynvml)
99
+ - Top processes by resource usage with friendly names and category badges
100
+ - Process descriptions and tooltips for 97 common applications
101
+ - Plain-English system health summaries
102
+
103
+ ### Intelligence
104
+ - OOM (out-of-memory) prediction with confidence scores and time-to-crash estimates
105
+ - Smart alerts with cooldowns (17+ configurable rules)
106
+ - Training progress detection (tqdm interception, stdout parsing)
107
+ - ETA estimation for long-running tasks
108
+ - L2 recommendations -- actionable suggestions from cross-signal analysis (12 rules)
109
+ - Built-in chatbot for natural language system health queries
110
+
111
+ ### LLM Health Monitoring
112
+ - Conversation health scoring (7 signals, 0-100 score) across Claude Code, Cursor, Windsurf, Ollama
113
+ - Real Claude Code session data via JSONL transcript reading (actual token counts)
114
+ - MCP session tracking with fatigue scoring and token estimation
115
+ - Ollama local LLM monitoring -- auto-detect, VRAM tracking, model load/unload
116
+ - LLM connection scanner -- detects 9 AI tool types running on your system
117
+ - Per-source health breakdown with combined worst-of scoring
118
+
119
+ ### LLM API Tracking
120
+ - Wrap OpenAI, Anthropic, and Google API clients to track token usage and cost
121
+ - Context window exhaustion prediction
122
+ - Latency degradation detection
123
+ - Cost calculation across 30+ models and 7 providers
124
+
125
+ ### Cloud Notebooks
126
+ - Google Colab: session time, GPU type changes, VRAM, storage, tier detection
127
+ - Kaggle: GPU quota tracking, session limits, output size, internet detection
128
+
129
+ ### Persistent Analytics
130
+ - Event pipeline with SQLite + FTS5 full-text search
131
+ - Query history by type, severity, or keyword
132
+ - 30-day retention with automatic pruning
133
+ - Separate analytics dashboard at port 8421
134
+
135
+ ### MCP Server (9 Tools)
136
+ - `get_system_metrics` -- full system snapshot (CPU, RAM, disk, network, GPU)
137
+ - `get_running_processes` -- top processes by CPU/memory with friendly names
138
+ - `predict_oom` -- memory exhaustion prediction with confidence
139
+ - `get_training_status` -- tracked task progress and ETAs
140
+ - `get_active_alerts` -- current monitoring alerts
141
+ - `check_context_health` -- conversation health score with component breakdown
142
+ - `get_recommendations` -- L2 actionable recommendations
143
+ - `query_history` -- search analytics event history
144
+ - `search_events` -- full-text search across stored events
145
+
146
+ ### Live Dashboard
147
+ - Real-time metrics with color-coded gauges (cyan/amber/red)
148
+ - Visual urgency indicators (amber glow at 60%, red pulse at 80%+)
149
+ - Conversation health accordion with per-source breakdown
150
+ - Connection badges for auto-detected LLM tools
151
+ - Memory trend chart (5-minute rolling)
152
+ - Process table with friendly names and hover tooltips
153
+ - OOM prediction display
154
+ - Alert banner with severity indicators
155
+ - Built-in chatbot ("Ask Bannin") with 15 intents
156
+ - Loading eye animation
157
+
158
+ ## API
159
+
160
+ The agent exposes a local REST API at `localhost:8420`:
161
+
162
+ | Endpoint | Method | Purpose |
163
+ |---|---|---|
164
+ | `/health` | GET | Agent alive check |
165
+ | `/status` | GET | Agent identity (hostname, OS, version, uptime) |
166
+ | `/metrics` | GET | Full system snapshot (CPU, RAM, disk, network, GPU) |
167
+ | `/processes` | GET | Top processes with friendly names and categories |
168
+ | `/summary` | GET | Plain-English system health summary |
169
+ | `/chat` | POST | Chatbot (natural language system health assistant) |
170
+ | `/alerts` | GET | Full alert history for this session |
171
+ | `/alerts/active` | GET | Currently active alerts |
172
+ | `/predictions/oom` | GET | OOM prediction with confidence |
173
+ | `/history/memory` | GET | Memory usage history over last N minutes |
174
+ | `/tasks` | GET | Tracked tasks (training progress, ETAs) |
175
+ | `/recommendations` | GET | L2 actionable recommendations |
176
+ | `/llm/usage` | GET | LLM session health and usage summary |
177
+ | `/llm/calls` | GET | Recent LLM API call history |
178
+ | `/llm/health` | GET | Unified conversation health score (combined + per-source) |
179
+ | `/llm/context` | GET | Context window exhaustion prediction |
180
+ | `/llm/latency` | GET | Response latency trend analysis |
181
+ | `/llm/connections` | GET | Auto-detected LLM tools running on system |
182
+ | `/ollama` | GET | Ollama local LLM status and loaded models |
183
+ | `/mcp/session` | POST | Receive MCP session health push |
184
+ | `/mcp/sessions` | GET | List all live MCP sessions |
185
+ | `/analytics/stats` | GET | Analytics store statistics |
186
+ | `/analytics/events` | GET | Query stored events with filters |
187
+ | `/analytics/search` | GET | Full-text search across events |
188
+ | `/analytics/timeline` | GET | Event timeline |
189
+ | `/platform` | GET | Cloud notebook platform info (Colab/Kaggle) |
190
+ | `/stream` | GET | Server-Sent Events for live dashboard updates |
191
+
192
+ ## Python API
193
+
194
+ ```python
195
+ import bannin
196
+
197
+ # Monitor system during a block of code
198
+ with bannin.watch():
199
+ train_model()
200
+
201
+ # Wrap an LLM client to track tokens and cost
202
+ import openai
203
+ client = bannin.wrap(openai.OpenAI())
204
+
205
+ # Track a specific scope
206
+ with bannin.track("my-experiment"):
207
+ response = client.chat.completions.create(...)
208
+ ```
209
+
210
+ ## CLI
211
+
212
+ ```bash
213
+ bannin start # Start the agent (dashboard at localhost:8420)
214
+ bannin start --port 9000 # Start on a custom port
215
+ bannin mcp # Start the MCP server (stdio transport)
216
+ bannin analytics # Start the analytics dashboard (port 8421)
217
+ bannin history # Query stored event history
218
+ bannin history --since 2h # Events from the last 2 hours
219
+ bannin history --search "OOM" # Full-text search
220
+ bannin history --json # Raw JSON output
221
+ ```
222
+
223
+ ## What's Coming
224
+
225
+ - Phone alerts (push notifications when tasks finish or systems need attention)
226
+ - Browser extension for ChatGPT, Claude.ai, and Gemini monitoring
227
+ - Context transfer -- carry conversation state to a fresh chat when health degrades
228
+ - macOS Apple Silicon GPU support
229
+ - Shareable dashboards via bannin.dev
230
+
231
+ ## Requirements
232
+
233
+ - Python 3.9+
234
+ - Works on Windows, macOS, and Linux
235
+
236
+ ## License
237
+
238
+ [MIT](LICENSE)
bannin-0.1.0/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Bannin
2
+
3
+ **番人** (Japanese for "watchman") — a universal monitoring agent for your machine, your LLMs, and your cloud notebooks.
4
+
5
+ *You hit run. You walk away. Then what?*
6
+
7
+ ---
8
+
9
+ ## What It Does
10
+
11
+ Bannin runs on your machine (or inside a cloud notebook) and monitors everything: CPU, RAM, GPU, disk, running processes, LLM conversation health, API usage, and cloud session health. It predicts out-of-memory crashes before they happen, scores your AI conversation quality, fires smart alerts, and gives you plain-English summaries of how your system is doing.
12
+
13
+ It also works as an **MCP server** — meaning AI coding tools (Claude Code, Cursor, Windsurf) can query your system health through natural conversation.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install bannin
19
+ ```
20
+
21
+ With GPU monitoring and MCP server support:
22
+
23
+ ```bash
24
+ pip install "bannin[all]"
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ **Start the agent:**
30
+
31
+ ```bash
32
+ bannin start
33
+ ```
34
+
35
+ **Open the dashboard:**
36
+
37
+ Visit [localhost:8420](http://localhost:8420) in your browser.
38
+
39
+ **Use with Claude Code (MCP):**
40
+
41
+ Add to your `.mcp.json`:
42
+
43
+ ```json
44
+ {
45
+ "mcpServers": {
46
+ "bannin": {
47
+ "command": "python",
48
+ "args": ["-m", "bannin.mcp"]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ Then ask Claude things like:
55
+ - "How's my system doing?"
56
+ - "What processes are using the most memory?"
57
+ - "Am I going to run out of RAM?"
58
+ - "How healthy is this conversation?"
59
+
60
+ ## Features
61
+
62
+ ### System Monitoring
63
+ - CPU, RAM, disk, network -- real-time with 30-minute history
64
+ - GPU monitoring (NVIDIA via pynvml)
65
+ - Top processes by resource usage with friendly names and category badges
66
+ - Process descriptions and tooltips for 97 common applications
67
+ - Plain-English system health summaries
68
+
69
+ ### Intelligence
70
+ - OOM (out-of-memory) prediction with confidence scores and time-to-crash estimates
71
+ - Smart alerts with cooldowns (17+ configurable rules)
72
+ - Training progress detection (tqdm interception, stdout parsing)
73
+ - ETA estimation for long-running tasks
74
+ - L2 recommendations -- actionable suggestions from cross-signal analysis (12 rules)
75
+ - Built-in chatbot for natural language system health queries
76
+
77
+ ### LLM Health Monitoring
78
+ - Conversation health scoring (7 signals, 0-100 score) across Claude Code, Cursor, Windsurf, Ollama
79
+ - Real Claude Code session data via JSONL transcript reading (actual token counts)
80
+ - MCP session tracking with fatigue scoring and token estimation
81
+ - Ollama local LLM monitoring -- auto-detect, VRAM tracking, model load/unload
82
+ - LLM connection scanner -- detects 9 AI tool types running on your system
83
+ - Per-source health breakdown with combined worst-of scoring
84
+
85
+ ### LLM API Tracking
86
+ - Wrap OpenAI, Anthropic, and Google API clients to track token usage and cost
87
+ - Context window exhaustion prediction
88
+ - Latency degradation detection
89
+ - Cost calculation across 30+ models and 7 providers
90
+
91
+ ### Cloud Notebooks
92
+ - Google Colab: session time, GPU type changes, VRAM, storage, tier detection
93
+ - Kaggle: GPU quota tracking, session limits, output size, internet detection
94
+
95
+ ### Persistent Analytics
96
+ - Event pipeline with SQLite + FTS5 full-text search
97
+ - Query history by type, severity, or keyword
98
+ - 30-day retention with automatic pruning
99
+ - Separate analytics dashboard at port 8421
100
+
101
+ ### MCP Server (9 Tools)
102
+ - `get_system_metrics` -- full system snapshot (CPU, RAM, disk, network, GPU)
103
+ - `get_running_processes` -- top processes by CPU/memory with friendly names
104
+ - `predict_oom` -- memory exhaustion prediction with confidence
105
+ - `get_training_status` -- tracked task progress and ETAs
106
+ - `get_active_alerts` -- current monitoring alerts
107
+ - `check_context_health` -- conversation health score with component breakdown
108
+ - `get_recommendations` -- L2 actionable recommendations
109
+ - `query_history` -- search analytics event history
110
+ - `search_events` -- full-text search across stored events
111
+
112
+ ### Live Dashboard
113
+ - Real-time metrics with color-coded gauges (cyan/amber/red)
114
+ - Visual urgency indicators (amber glow at 60%, red pulse at 80%+)
115
+ - Conversation health accordion with per-source breakdown
116
+ - Connection badges for auto-detected LLM tools
117
+ - Memory trend chart (5-minute rolling)
118
+ - Process table with friendly names and hover tooltips
119
+ - OOM prediction display
120
+ - Alert banner with severity indicators
121
+ - Built-in chatbot ("Ask Bannin") with 15 intents
122
+ - Loading eye animation
123
+
124
+ ## API
125
+
126
+ The agent exposes a local REST API at `localhost:8420`:
127
+
128
+ | Endpoint | Method | Purpose |
129
+ |---|---|---|
130
+ | `/health` | GET | Agent alive check |
131
+ | `/status` | GET | Agent identity (hostname, OS, version, uptime) |
132
+ | `/metrics` | GET | Full system snapshot (CPU, RAM, disk, network, GPU) |
133
+ | `/processes` | GET | Top processes with friendly names and categories |
134
+ | `/summary` | GET | Plain-English system health summary |
135
+ | `/chat` | POST | Chatbot (natural language system health assistant) |
136
+ | `/alerts` | GET | Full alert history for this session |
137
+ | `/alerts/active` | GET | Currently active alerts |
138
+ | `/predictions/oom` | GET | OOM prediction with confidence |
139
+ | `/history/memory` | GET | Memory usage history over last N minutes |
140
+ | `/tasks` | GET | Tracked tasks (training progress, ETAs) |
141
+ | `/recommendations` | GET | L2 actionable recommendations |
142
+ | `/llm/usage` | GET | LLM session health and usage summary |
143
+ | `/llm/calls` | GET | Recent LLM API call history |
144
+ | `/llm/health` | GET | Unified conversation health score (combined + per-source) |
145
+ | `/llm/context` | GET | Context window exhaustion prediction |
146
+ | `/llm/latency` | GET | Response latency trend analysis |
147
+ | `/llm/connections` | GET | Auto-detected LLM tools running on system |
148
+ | `/ollama` | GET | Ollama local LLM status and loaded models |
149
+ | `/mcp/session` | POST | Receive MCP session health push |
150
+ | `/mcp/sessions` | GET | List all live MCP sessions |
151
+ | `/analytics/stats` | GET | Analytics store statistics |
152
+ | `/analytics/events` | GET | Query stored events with filters |
153
+ | `/analytics/search` | GET | Full-text search across events |
154
+ | `/analytics/timeline` | GET | Event timeline |
155
+ | `/platform` | GET | Cloud notebook platform info (Colab/Kaggle) |
156
+ | `/stream` | GET | Server-Sent Events for live dashboard updates |
157
+
158
+ ## Python API
159
+
160
+ ```python
161
+ import bannin
162
+
163
+ # Monitor system during a block of code
164
+ with bannin.watch():
165
+ train_model()
166
+
167
+ # Wrap an LLM client to track tokens and cost
168
+ import openai
169
+ client = bannin.wrap(openai.OpenAI())
170
+
171
+ # Track a specific scope
172
+ with bannin.track("my-experiment"):
173
+ response = client.chat.completions.create(...)
174
+ ```
175
+
176
+ ## CLI
177
+
178
+ ```bash
179
+ bannin start # Start the agent (dashboard at localhost:8420)
180
+ bannin start --port 9000 # Start on a custom port
181
+ bannin mcp # Start the MCP server (stdio transport)
182
+ bannin analytics # Start the analytics dashboard (port 8421)
183
+ bannin history # Query stored event history
184
+ bannin history --since 2h # Events from the last 2 hours
185
+ bannin history --search "OOM" # Full-text search
186
+ bannin history --json # Raw JSON output
187
+ ```
188
+
189
+ ## What's Coming
190
+
191
+ - Phone alerts (push notifications when tasks finish or systems need attention)
192
+ - Browser extension for ChatGPT, Claude.ai, and Gemini monitoring
193
+ - Context transfer -- carry conversation state to a fresh chat when health degrades
194
+ - macOS Apple Silicon GPU support
195
+ - Shareable dashboards via bannin.dev
196
+
197
+ ## Requirements
198
+
199
+ - Python 3.9+
200
+ - Works on Windows, macOS, and Linux
201
+
202
+ ## License
203
+
204
+ [MIT](LICENSE)
@@ -0,0 +1,139 @@
1
+ from __future__ import annotations
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ import threading
6
+ from types import TracebackType
7
+
8
+ from bannin.core.collector import get_all_metrics
9
+ from bannin.llm.wrapper import wrap
10
+ from bannin.llm.tracker import track
11
+
12
+
13
+ class Bannin:
14
+ """Main Bannin agent — collects metrics and exposes API."""
15
+
16
+ def __init__(self, port: int = 8420) -> None:
17
+ self._port = port
18
+ self._server_thread: threading.Thread | None = None
19
+ self._lock = threading.Lock()
20
+ self._running = False
21
+
22
+ def start(self) -> None:
23
+ """Start the agent API server in a background thread."""
24
+ import uvicorn
25
+ from bannin.api import app
26
+
27
+ with self._lock:
28
+ if self._running:
29
+ return
30
+ self._running = True
31
+ self._server_thread = threading.Thread(
32
+ target=uvicorn.run,
33
+ kwargs={"app": app, "host": "127.0.0.1", "port": self._port, "log_level": "warning"},
34
+ daemon=True,
35
+ )
36
+ self._server_thread.start()
37
+
38
+ def stop(self) -> None:
39
+ """Mark the agent as stopped. The daemon thread exits with the process."""
40
+ with self._lock:
41
+ self._running = False
42
+ self._server_thread = None
43
+
44
+ def metrics(self) -> dict:
45
+ """Get a snapshot of current system metrics."""
46
+ from bannin.core.gpu import get_gpu_metrics
47
+ data = get_all_metrics()
48
+ data["gpu"] = get_gpu_metrics()
49
+ return data
50
+
51
+
52
+ def progress(name: str, current: int, total: int | None = None, *, port: int = 8420) -> None:
53
+ """Report training progress to the running Bannin agent.
54
+
55
+ Call this from any script to push progress to the dashboard without
56
+ needing bannin.watch(). The CLI agent must be running separately.
57
+ Silently ignores network failures (agent not running, connection refused).
58
+ Raises ValueError for obviously invalid inputs.
59
+
60
+ The HTTP POST has a 2-second timeout. For tight training loops, consider
61
+ calling every N iterations rather than every single step.
62
+
63
+ Usage:
64
+ import bannin
65
+ for epoch in range(1, 11):
66
+ train_epoch()
67
+ bannin.progress("Training GPT", current=epoch, total=10)
68
+ """
69
+ if not name or not isinstance(name, str):
70
+ raise ValueError("name must be a non-empty string")
71
+ if not isinstance(current, int) or current < 0:
72
+ raise ValueError("current must be a non-negative integer")
73
+ if total is not None and (not isinstance(total, int) or total < 1):
74
+ raise ValueError("total must be a positive integer or None")
75
+
76
+ import json
77
+ import os
78
+ import urllib.request
79
+
80
+ payload = json.dumps({
81
+ "name": name,
82
+ "current": current,
83
+ "total": total,
84
+ "pid": os.getpid(),
85
+ }).encode()
86
+
87
+ try:
88
+ req = urllib.request.Request(
89
+ f"http://127.0.0.1:{port}/tasks",
90
+ data=payload,
91
+ headers={"Content-Type": "application/json"},
92
+ method="POST",
93
+ )
94
+ urllib.request.urlopen(req, timeout=2)
95
+ except Exception:
96
+ # Fire-and-forget: agent may not be running. No logging here because
97
+ # this function is called from user scripts that may not have bannin
98
+ # logging configured. The agent-side POST /tasks endpoint logs errors.
99
+ pass
100
+
101
+
102
+ class watch:
103
+ """Context manager that runs the Bannin agent during a block of code.
104
+
105
+ Usage:
106
+ with bannin.watch():
107
+ train_model()
108
+ """
109
+
110
+ def __init__(self, port: int = 8420) -> None:
111
+ self._agent = Bannin(port=port)
112
+
113
+ def __enter__(self) -> Bannin:
114
+ self._agent.start()
115
+ self._history = None
116
+ self._progress = None
117
+ try:
118
+ from bannin.intelligence.history import MetricHistory
119
+ self._history = MetricHistory.get()
120
+ self._history.start()
121
+ from bannin.intelligence.progress import ProgressTracker
122
+ self._progress = ProgressTracker.get()
123
+ self._progress.hook_all()
124
+ except Exception:
125
+ if self._progress is not None:
126
+ self._progress.unhook_all()
127
+ if self._history is not None:
128
+ self._history.stop()
129
+ self._agent.stop()
130
+ raise
131
+ return self._agent
132
+
133
+ def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> bool:
134
+ if self._progress is not None:
135
+ self._progress.unhook_all()
136
+ if self._history is not None:
137
+ self._history.stop()
138
+ self._agent.stop()
139
+ return False
@@ -0,0 +1,3 @@
1
+ """Bannin analytics -- persistent event storage and querying."""
2
+
3
+ from __future__ import annotations