telemux 1.0.5__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.
@@ -0,0 +1,478 @@
1
+ Metadata-Version: 2.4
2
+ Name: telemux
3
+ Version: 1.0.5
4
+ Summary: Bidirectional Telegram integration for tmux sessions - monitor commands and interact with agents
5
+ Author-email: Marco Almazan <marco@example.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/malmazan/telemux
8
+ Project-URL: Repository, https://github.com/malmazan/telemux
9
+ Project-URL: Issues, https://github.com/malmazan/telemux/issues
10
+ Keywords: telegram,tmux,notifications,monitoring,agent,automation
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Communications :: Chat
25
+ Classifier: Topic :: System :: Monitoring
26
+ Classifier: Topic :: System :: Systems Administration
27
+ Classifier: Topic :: Utilities
28
+ Requires-Python: >=3.7
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: requests<3.0.0,>=2.25.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
34
+ Requires-Dist: pytest-mock>=3.11.1; extra == "dev"
35
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
36
+ Requires-Dist: responses>=0.23.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # TeleMux
40
+
41
+ **Bidirectional Telegram integration for tmux sessions** - Monitor commands, interact with agents, and stay connected to your terminal from anywhere.
42
+
43
+ ## Features
44
+
45
+ - **One-way notifications**: Send alerts to Telegram when commands complete
46
+ - **Bidirectional communication**: Interact with tmux sessions via Telegram
47
+ - **Agent support**: Create interactive agents that can receive replies
48
+ - **Session routing**: Messages automatically delivered to the correct tmux session
49
+ - **Daemon-based**: Runs as a background service in tmux
50
+ - **Shell integration**: Simple shell functions for easy use
51
+ - **Secure**: Configuration files are automatically protected (chmod 600)
52
+
53
+ ## Installation
54
+
55
+ ### Via pip (Recommended)
56
+
57
+ ```bash
58
+ # Install the package
59
+ pip install telemux
60
+
61
+ # Run the interactive installer
62
+ telemux install
63
+
64
+ # Start the listener daemon
65
+ telemux start
66
+ ```
67
+
68
+ ### From source
69
+
70
+ ```bash
71
+ # Clone the repository
72
+ git clone https://github.com/malmazan/telemux.git
73
+ cd telemux
74
+
75
+ # Install in development mode
76
+ pip install -e .
77
+
78
+ # Run the installer
79
+ telemux install
80
+ ```
81
+
82
+ ## Quick Start
83
+
84
+ ### 1. Create a Telegram Bot
85
+
86
+ 1. Open Telegram and search for [@BotFather](https://t.me/BotFather)
87
+ 2. Send `/newbot` and follow the prompts
88
+ 3. Save the bot token provided
89
+
90
+ ### 2. Install TeleMux
91
+
92
+ ```bash
93
+ # Install via pip
94
+ pip install telemux
95
+
96
+ # Run the interactive installer
97
+ telemux install
98
+ ```
99
+
100
+ The installer will:
101
+ - Check prerequisites (tmux, python3, curl)
102
+ - Validate your bot token
103
+ - Auto-detect available chats (with retry logic)
104
+ - Create configuration files
105
+ - Install shell functions
106
+ - Test the connection
107
+
108
+ ### 3. Start the Listener
109
+
110
+ ```bash
111
+ # Start the daemon
112
+ telemux start
113
+
114
+ # Check status
115
+ telemux status
116
+
117
+ # View logs
118
+ telemux logs
119
+ ```
120
+
121
+ ### 4. Use Shell Functions
122
+
123
+ ```bash
124
+ # Send a simple notification
125
+ tg_alert "Build complete!"
126
+
127
+ # Send a message and receive replies (auto-detects tmux session name)
128
+ tg_agent "Ready to deploy to production?"
129
+ # Reply via Telegram: "session-name: yes"
130
+ # The reply appears directly in your terminal
131
+
132
+ # Get notified when a command completes
133
+ npm run build && tg_done
134
+ ```
135
+
136
+ ## Commands
137
+
138
+ ### Control Commands
139
+
140
+ ```bash
141
+ telemux start # Start the listener daemon
142
+ telemux stop # Stop the listener daemon
143
+ telemux restart # Restart the listener daemon
144
+ telemux status # Check daemon status
145
+ telemux logs # View listener logs (tail -f)
146
+ telemux attach # Attach to the listener tmux session
147
+ telemux cleanup # Rotate and clean up log files
148
+ telemux doctor # Run health check and diagnose issues
149
+ telemux install # Run interactive installer
150
+ ```
151
+
152
+ ### Shortcuts
153
+
154
+ For convenience, all commands have `tg-` shortcuts:
155
+
156
+ ```bash
157
+ tg-start # Same as: telemux start
158
+ tg-stop # Same as: telemux stop
159
+ tg-status # Same as: telemux status
160
+ tg-logs # Same as: telemux logs
161
+ ```
162
+
163
+ ## Shell Functions
164
+
165
+ After installation, these functions are available in your shell:
166
+
167
+ ### `tg_alert`
168
+
169
+ Send one-way notifications to Telegram:
170
+
171
+ ```bash
172
+ tg_alert "Message text"
173
+ ```
174
+
175
+ **Examples:**
176
+
177
+ ```bash
178
+ # Simple notification
179
+ tg_alert "Server is ready"
180
+
181
+ # Notify when command completes
182
+ npm install && tg_alert "Dependencies installed"
183
+
184
+ # Multiline messages
185
+ tg_alert "Deploy complete
186
+ - 50 files updated
187
+ - 0 errors"
188
+ ```
189
+
190
+ ### `tg_agent`
191
+
192
+ Send messages and receive replies via Telegram (automatically uses your tmux session name):
193
+
194
+ ```bash
195
+ tg_agent "Message text"
196
+ ```
197
+
198
+ **Examples:**
199
+
200
+ ```bash
201
+ # Ask a question (inside a tmux session named "deploy")
202
+ tg_agent "Ready to deploy to production?"
203
+
204
+ # Wait for user response via Telegram
205
+ # User replies: "deploy: yes, proceed"
206
+ # Reply appears in your terminal
207
+
208
+ # Use in scripts (inside a tmux session named "approval")
209
+ tg_agent "Approve release v2.0?"
210
+ # Returns the session name, user responds via Telegram
211
+ # Check incoming message for approval
212
+ ```
213
+
214
+ ### `tg_done`
215
+
216
+ Automatically notify when the previous command completes:
217
+
218
+ ```bash
219
+ npm run build && tg_done
220
+ ```
221
+
222
+ This sends a notification with:
223
+ - Command that ran
224
+ - Exit code (success/failure)
225
+ - Timestamp
226
+
227
+ ## Bidirectional Communication
228
+
229
+ TeleMux uses **session-based routing** for bidirectional communication:
230
+
231
+ ### Sending Messages from Terminal
232
+
233
+ ```bash
234
+ # In tmux session named "deploy"
235
+ tg_agent "Should I proceed with deployment?"
236
+ ```
237
+
238
+ This sends a message to Telegram with instructions on how to reply. The session name is automatically detected.
239
+
240
+ ### Replying from Telegram
241
+
242
+ Reply with the format: `session-name: your message`
243
+
244
+ ```
245
+ deploy: yes, proceed with deployment
246
+ ```
247
+
248
+ The reply is automatically routed to the correct tmux session and appears in your terminal.
249
+
250
+ ### Security
251
+
252
+ - Messages are routed **only** to existing tmux sessions
253
+ - User input is sanitized to prevent command injection
254
+ - Session names are validated before routing
255
+ - No session names are revealed in error messages
256
+
257
+ ## Configuration
258
+
259
+ Configuration is stored in `~/.telemux/`:
260
+
261
+ ```
262
+ ~/.telemux/
263
+ ├── telegram_config # Bot token and chat ID (chmod 600)
264
+ ├── telegram_listener.log # Listener daemon logs
265
+ ├── telegram_errors.log # Error logs
266
+ ├── message_queue/ # Message routing data
267
+ │ ├── outgoing.log # Sent messages
268
+ │ ├── incoming.log # Received messages
269
+ │ └── archive/ # Rotated logs
270
+ └── shell_functions.sh # Shell integration functions
271
+ ```
272
+
273
+ ### Environment Variables
274
+
275
+ You can override configuration with environment variables:
276
+
277
+ ```bash
278
+ export TELEMUX_TG_BOT_TOKEN="your-bot-token"
279
+ export TELEMUX_TG_CHAT_ID="your-chat-id"
280
+ export TELEMUX_LOG_LEVEL="DEBUG" # DEBUG, INFO, WARNING, ERROR
281
+ ```
282
+
283
+ ## Log Management
284
+
285
+ Logs are automatically rotated when they exceed 10MB:
286
+
287
+ ```bash
288
+ # Manual log rotation
289
+ telemux cleanup
290
+
291
+ # Install automatic monthly cleanup
292
+ telemux cleanup --install-cron
293
+ ```
294
+
295
+ Archives are stored in `~/.telemux/message_queue/archive/` and compressed with gzip.
296
+
297
+ ## Troubleshooting
298
+
299
+ ### Run Health Check
300
+
301
+ ```bash
302
+ telemux doctor
303
+ ```
304
+
305
+ This checks:
306
+ - Prerequisites (tmux, python3)
307
+ - Configuration files
308
+ - Telegram bot connection
309
+ - Listener daemon status
310
+ - Log files
311
+
312
+ ### Common Issues
313
+
314
+ **Listener won't start:**
315
+ ```bash
316
+ # Check if it's already running
317
+ telemux status
318
+
319
+ # View logs for errors
320
+ telemux logs
321
+
322
+ # Restart the listener
323
+ telemux restart
324
+ ```
325
+
326
+ **Messages not being received:**
327
+ ```bash
328
+ # Check listener status
329
+ telemux status
330
+
331
+ # Verify configuration
332
+ cat ~/.telemux/telegram_config
333
+
334
+ # Test bot connection
335
+ telemux doctor
336
+ ```
337
+
338
+ **Shell functions not available:**
339
+ ```bash
340
+ # Reload your shell configuration
341
+ source ~/.zshrc # or ~/.bashrc
342
+
343
+ # Verify functions are sourced
344
+ type tg_alert
345
+ ```
346
+
347
+ ## Examples
348
+
349
+ ### Long-Running Build Notification
350
+
351
+ ```bash
352
+ #!/bin/bash
353
+ # Build script with notification
354
+
355
+ echo "Starting build..."
356
+ tg_alert "Build started for project-x"
357
+
358
+ npm run build
359
+ if [ $? -eq 0 ]; then
360
+ tg_alert "Build succeeded!"
361
+ else
362
+ tg_alert "Build failed! Check logs."
363
+ fi
364
+ ```
365
+
366
+ ### Interactive Deployment Agent
367
+
368
+ ```bash
369
+ #!/bin/bash
370
+ # Deployment with approval (run in tmux session named "deploy")
371
+
372
+ tg_agent "Ready to deploy v2.0 to production?"
373
+
374
+ # User responds via Telegram: "deploy: yes"
375
+ # Response appears in terminal
376
+
377
+ read -p "Proceed with deployment? " response
378
+ if [[ "$response" == *"yes"* ]]; then
379
+ ./deploy.sh
380
+ tg_alert "Deployment complete!"
381
+ fi
382
+ ```
383
+
384
+ ### Multi-Step Workflow
385
+
386
+ ```bash
387
+ #!/bin/bash
388
+ # Complex workflow with multiple checkpoints (run in tmux session named "migration")
389
+
390
+ tg_alert "Starting migration workflow..."
391
+
392
+ # Step 1: Backup
393
+ tg_agent "Backup database before migration?"
394
+ # Wait for approval...
395
+
396
+ # Step 2: Migration
397
+ ./run-migration.sh && tg_done
398
+
399
+ # Step 3: Verification
400
+ tg_agent "Verify migration results?"
401
+ # Wait for verification...
402
+
403
+ tg_alert "Migration workflow complete!"
404
+ ```
405
+
406
+ ## Development
407
+
408
+ ### Running Tests
409
+
410
+ ```bash
411
+ # Install development dependencies
412
+ pip install -e ".[dev]"
413
+
414
+ # Run tests
415
+ pytest
416
+
417
+ # Run with coverage
418
+ pytest --cov=telemux --cov-report=term-missing
419
+ ```
420
+
421
+ ### Project Structure
422
+
423
+ ```
424
+ telemux/
425
+ ├── telemux/
426
+ │ ├── __init__.py # Package initialization
427
+ │ ├── cli.py # Main CLI entry point
428
+ │ ├── control.py # Daemon control (start, stop, status)
429
+ │ ├── listener.py # Telegram listener daemon
430
+ │ ├── installer.py # Interactive installer
431
+ │ ├── cleanup.py # Log rotation and cleanup
432
+ │ ├── config.py # Configuration management
433
+ │ └── shell_functions.sh # Shell integration
434
+ ├── examples/ # Example scripts
435
+ ├── tests/ # Test suite
436
+ ├── pyproject.toml # Package metadata and dependencies
437
+ ├── MANIFEST.in # Package file manifest
438
+ └── README.md # This file
439
+ ```
440
+
441
+ ## Requirements
442
+
443
+ - Python 3.7+
444
+ - tmux
445
+ - curl
446
+ - requests library (automatically installed)
447
+
448
+ ## License
449
+
450
+ MIT License - see LICENSE file for details
451
+
452
+ ## Contributing
453
+
454
+ Contributions are welcome! Please:
455
+
456
+ 1. Fork the repository
457
+ 2. Create a feature branch
458
+ 3. Make your changes
459
+ 4. Add tests if applicable
460
+ 5. Submit a pull request
461
+
462
+ ## Changelog
463
+
464
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
465
+
466
+ ## Support
467
+
468
+ - GitHub Issues: https://github.com/malmazan/telemux/issues
469
+ - Documentation: https://github.com/malmazan/telemux
470
+
471
+ ## Credits
472
+
473
+ Created by Marco Almazan
474
+
475
+ ## Related Projects
476
+
477
+ - [tmux](https://github.com/tmux/tmux) - Terminal multiplexer
478
+ - [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) - Telegram Bot API wrapper
@@ -0,0 +1,14 @@
1
+ telemux/__init__.py,sha256=bYMKFY_ar0CHAF3jlWx4KR7su5ksgWdMi9-gTpKXMxE,528
2
+ telemux/cleanup.py,sha256=2os7--Zgt2yAWaNDNBKlFhl0K03qEgXVzRfqJ0vugaI,5037
3
+ telemux/cli.py,sha256=gDRSU8ek9QPktnc9IWufx091oImUS3EaHvqghkavjq4,2841
4
+ telemux/config.py,sha256=ZEBPys_guJAydeksfIFpJQ5wRVzF95NYrX2tfqQww-s,2103
5
+ telemux/control.py,sha256=4bHF3o-jrqq7TNtQjNmcMYEpggUN5SEH9SDYQr3nG14,9333
6
+ telemux/installer.py,sha256=x6p46oYhirdU_odxo2jhCtQFkpssHNOkHIZgKqwgWeM,13681
7
+ telemux/listener.py,sha256=FRX4gmhhM8ufByIn-7GFn-5yA1psjLtpHeb8_Ekcph8,11831
8
+ telemux/shell_functions.sh,sha256=urkv7QllehgGczZgAa5DLrFRxnO7Fy10AtgDToik8w4,3586
9
+ telemux-1.0.5.dist-info/licenses/LICENSE,sha256=dDp-Qt-v7Zi0aUHsgKxLdeWcP-qO-BtCmtP5T43Z6VI,1070
10
+ telemux-1.0.5.dist-info/METADATA,sha256=yfNXauBOwf9-D0HOZi4yd5SpTiEIMgqEd7oJvi_7A4o,11090
11
+ telemux-1.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ telemux-1.0.5.dist-info/entry_points.txt,sha256=mxK4w1flc7W4lj4tAHyDr4k_KOWmwmuqXw3cWmMZ7Dw,527
13
+ telemux-1.0.5.dist-info/top_level.txt,sha256=VSZ88IJhbt7XXwzMYBbFQMuXy-Q01JkzFXKn8ELixYw,8
14
+ telemux-1.0.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,15 @@
1
+ [console_scripts]
2
+ telemux = telemux.cli:main
3
+ telemux-attach = telemux.control:attach
4
+ telemux-cleanup = telemux.cleanup:main
5
+ telemux-doctor = telemux.control:doctor
6
+ telemux-install = telemux.installer:main
7
+ telemux-logs = telemux.control:logs
8
+ telemux-restart = telemux.control:restart
9
+ telemux-start = telemux.control:start
10
+ telemux-status = telemux.control:status
11
+ telemux-stop = telemux.control:stop
12
+ tg-logs = telemux.control:logs
13
+ tg-start = telemux.control:start
14
+ tg-status = telemux.control:status
15
+ tg-stop = telemux.control:stop
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Marco Almazan
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.
@@ -0,0 +1 @@
1
+ telemux