tmux4ssh 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.
tmux4ssh-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,475 @@
1
+ Metadata-Version: 2.4
2
+ Name: tmux4ssh
3
+ Version: 0.1.0
4
+ Summary: Execute remote commands via SSH in tmux sessions with real-time output streaming
5
+ Author: Gaofeng Fan
6
+ License: Apache 2.0
7
+ Project-URL: Homepage, https://github.com/circuitmuggle/tmux4ssh
8
+ Project-URL: Repository, https://github.com/circuitmuggle/tmux4ssh
9
+ Keywords: ssh,tmux,remote,command,automation
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: paramiko>=3.0.0
24
+ Requires-Dist: keyring>=24.0.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
28
+ Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
29
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
30
+ Requires-Dist: mypy>=1.8.0; extra == "dev"
31
+ Requires-Dist: pre-commit>=3.6.0; extra == "dev"
32
+ Requires-Dist: types-paramiko>=3.0.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # tmux4ssh
36
+
37
+ Execute remote commands via SSH in tmux sessions with real-time output streaming and batch mode.
38
+
39
+ The purpose of this project is to facilitate long-running simulations, such as Spectre, on a remote Linux server under unstable internet connections, when the user does not have root access to the server and relies on specialized CAD software such as Cadence Spectre.
40
+
41
+ ## Features
42
+
43
+ - **Real-time output streaming** - See command output as it happens
44
+ - **Tmux-based execution** - Commands run in persistent tmux sessions
45
+ - **Concurrent execution** - Run multiple commands in parallel with `--new`
46
+ - **Auto-new session** - Automatically creates new session if command already running (default: on)
47
+ - **Directory inheritance** - `--new` sessions inherit current directory from default session
48
+ - **Auto-cleanup** - `--new` sessions automatically terminate when commands complete
49
+ - **Running command detection** - Prevents accidental command conflicts
50
+ - **Session management** - List running commands, attach/reattach to sessions, cleanup idle sessions
51
+ - **Permanent log storage** - Timestamped logs preserved in `~/tmux_ssh_logs/`
52
+ - **Credential management** - Securely stores SSH credentials in system keyring
53
+ - **Timeout support** - Configurable idle (default: 1 hour) and total timeouts
54
+ - **Server change detection** - Warns when load-balanced hostname resolves to different server
55
+
56
+ ## Why tmux4ssh?
57
+
58
+ Standard SSH has limitations for long-running or critical remote tasks:
59
+
60
+ | Scenario | Standard SSH | tmux4ssh |
61
+ |----------|--------------|----------|
62
+ | Internet drops mid-command | Command killed (SIGHUP) | Command keeps running in tmux |
63
+ | Check progress after disconnect | Not possible | `tmux4ssh --attach` |
64
+ | Run concurrent commands | Manual session management | `tmux4ssh --new` |
65
+ | Stream output to local terminal | Works, but lost on disconnect | Persistent logs + reattach |
66
+
67
+ **The manual workaround** without tmux4ssh:
68
+ ```bash
69
+ ssh -t user@host # Interactive login
70
+ tmux new -s mysession # Create tmux session
71
+ ./long_running_script.sh # Run command
72
+ # Ctrl+B, D to detach
73
+ # ... later, after reconnecting ...
74
+ ssh -t user@host
75
+ tmux attach -t mysession # Hope you remember the session name
76
+ ```
77
+
78
+ **With tmux4ssh:**
79
+ ```bash
80
+ tmux4ssh "./long_running_script.sh" # Just run it
81
+ # ... connection drops, reconnect later ...
82
+ tmux4ssh --attach # Resume output streaming
83
+ ```
84
+
85
+ ## Installation
86
+
87
+ ### Option 1: Install as Package (Recommended)
88
+
89
+ ```bash
90
+ # Install in development mode
91
+ pip install -e ".[dev]"
92
+
93
+ # Install pre-commit hooks
94
+ pre-commit install
95
+ ```
96
+
97
+ **Requirements:** Python 3.10 or higher
98
+
99
+ ### Option 2: Use Prototype Without Installation
100
+
101
+ If you want to test without installing the package, use the standalone prototype script:
102
+
103
+ ```bash
104
+ # Navigate to prototype directory
105
+ cd prototype
106
+
107
+ # Run directly with Python
108
+ python3 tmux_ssh.py -H myserver.com -U myuser "hostname"
109
+ ```
110
+
111
+ See `prototype/README.md` for more details.
112
+
113
+ ### Uninstall
114
+
115
+ ```bash
116
+ pip uninstall tmux4ssh
117
+ ```
118
+
119
+ ## Usage
120
+
121
+ ### Basic Commands
122
+
123
+ ```bash
124
+ # SSH-compatible syntax (recommended)
125
+ tmux4ssh user@host "command"
126
+ tmux4ssh user@host:2222 "command" # With custom port
127
+ tmux4ssh host "command" # Uses saved username
128
+
129
+ # Flag-based syntax (also supported)
130
+ tmux4ssh -H myserver.com -U myuser "hostname"
131
+ tmux4ssh -p 2222 -H myserver.com -U myuser "hostname"
132
+
133
+ # Subsequent runs: host/user are remembered automatically
134
+ tmux4ssh "ls -la"
135
+ tmux4ssh "pwd"
136
+
137
+ # Override saved settings when needed
138
+ tmux4ssh -H otherserver.com "hostname"
139
+
140
+ # Set idle timeout (exit if no output for N seconds, default: 3600)
141
+ tmux4ssh -i 7200 "long_running_command"
142
+
143
+ # Set total timeout
144
+ tmux4ssh -t 3600 -i 1800 "very_long_command"
145
+ ```
146
+
147
+ ### Command Quoting
148
+
149
+ **When are quotes required?** Use quotes when your command contains:
150
+
151
+ - **Shell operators**: `&&`, `||`, `;`, `|`, `>`, `<`, `>>`, `2>&1`
152
+ - **Variable expansion**: `$VAR`, `$(command)`, backticks
153
+ - **Wildcards**: `*`, `?`, `[...]`
154
+ - **Spaces in arguments**: paths or strings with spaces
155
+
156
+ ```bash
157
+ # REQUIRED: Commands with shell operators
158
+ tmux4ssh user@host "cmd1 && cmd2" # Chain commands
159
+ tmux4ssh user@host "cmd1 || cmd2" # OR operator
160
+ tmux4ssh user@host "cmd1; cmd2" # Sequential
161
+ tmux4ssh user@host "cat file | grep pattern" # Pipe
162
+ tmux4ssh user@host "echo hello > output.txt" # Redirect
163
+
164
+ # REQUIRED: Commands with special characters
165
+ tmux4ssh user@host 'echo $HOME' # Preserve $HOME for remote
166
+ tmux4ssh user@host "ls *.txt" # Wildcards
167
+ tmux4ssh user@host "cd '/path with spaces'" # Paths with spaces
168
+
169
+ # OPTIONAL: Simple commands (quotes work but optional)
170
+ tmux4ssh user@host hostname # Single word - OK
171
+ tmux4ssh user@host "hostname" # Also OK
172
+ tmux4ssh user@host ls -la /tmp # May fail (see note below)
173
+ tmux4ssh user@host "ls -la /tmp" # Safer with quotes
174
+ ```
175
+
176
+ **Note on flags starting with `-`**: Arguments like `-la` may be interpreted as tmux4ssh flags. Always quote commands with such arguments:
177
+
178
+ ```bash
179
+ # Problematic: -la might be parsed as a flag
180
+ tmux4ssh user@host ls -la
181
+
182
+ # Safe: Quote the entire command
183
+ tmux4ssh user@host "ls -la"
184
+ ```
185
+
186
+ **Best practice**: Always quote your command string to avoid surprises.
187
+
188
+ ### Saved Settings
189
+
190
+ tmux4ssh automatically saves your connection settings to `~/.tmux_ssh_config`:
191
+
192
+ - **Host** (`-H`): Remote hostname
193
+ - **User** (`-U`): SSH username
194
+ - **Port** (`-p`): SSH port (default: 22)
195
+ - **Last server**: Actual server hostname (for load-balancer detection)
196
+ - **Auto-new setting**: Whether to auto-create sessions
197
+
198
+ This means you only need to specify connection details once. All subsequent commands will use the saved settings automatically.
199
+
200
+ ### Concurrent Execution
201
+
202
+ By default, tmux4ssh automatically creates a new session when you run a command while another is already running:
203
+
204
+ ```bash
205
+ # First command runs in default session
206
+ tmux4ssh "command1"
207
+
208
+ # Second command auto-creates new session for concurrent execution
209
+ tmux4ssh "command2"
210
+ # Output: [*] Session 'remote_task' is busy, creating 'task_a1b2c3d4' for concurrent execution...
211
+ ```
212
+
213
+ You can also explicitly control this behavior:
214
+
215
+ ```bash
216
+ # Explicitly create new session (always creates fresh session)
217
+ tmux4ssh --new "command"
218
+
219
+ # Disable auto-new, block if session is busy
220
+ tmux4ssh --no-auto "command"
221
+
222
+ # Force execution (kills any running command in session)
223
+ tmux4ssh --force "command"
224
+ ```
225
+
226
+ ### Session Management
227
+
228
+ ```bash
229
+ # List all running commands/sessions
230
+ tmux4ssh --list
231
+
232
+ # Attach to a running session (auto-detect if only one)
233
+ tmux4ssh --attach
234
+
235
+ # Attach to a specific session
236
+ tmux4ssh --attach task_a1b2c3d4
237
+
238
+ # Clean up idle task_* sessions (keeps remote_task)
239
+ tmux4ssh --cleanup
240
+ ```
241
+
242
+ When a command times out, you can resume streaming its output:
243
+ ```bash
244
+ # After timeout message:
245
+ # [*] Idle timeout (3600s) reached. Command still running in tmux.
246
+ # [*] Use 'tmux4ssh --attach' to resume streaming the output.
247
+
248
+ tmux4ssh --attach
249
+ ```
250
+
251
+ ### Load-Balanced Hostnames
252
+
253
+ If your hostname resolves to multiple backend servers (DNS round-robin or load balancer), tmux4ssh will warn you when you connect to a different server than before:
254
+
255
+ ```
256
+ [!] WARNING: Server changed!
257
+ Previous server: node01.cluster.example.com
258
+ Current server: node02.cluster.example.com
259
+ [!] Your tmux sessions from 'node01.cluster.example.com' are NOT available on 'node02.cluster.example.com'.
260
+ [*] To access previous sessions, connect directly to: node01.cluster.example.com
261
+ ```
262
+
263
+ **Recommendation**: For consistent tmux session access, use specific server hostnames instead of load-balanced hostnames:
264
+ ```bash
265
+ # Instead of this (may connect to different servers):
266
+ tmux4ssh -H cluster.example.com "command"
267
+
268
+ # Use this (always same server):
269
+ tmux4ssh -H node01.cluster.example.com "command"
270
+ ```
271
+
272
+ ### Credential Management
273
+
274
+ ```bash
275
+ # Clear stored credentials
276
+ tmux4ssh --clear
277
+ ```
278
+
279
+ **Tip: SSH Key Authentication**
280
+
281
+ Setting up SSH keys eliminates password prompts for every command:
282
+
283
+ ```bash
284
+ # Generate key (if you don't have one)
285
+ ssh-keygen -t ed25519
286
+
287
+ # Copy public key to remote server
288
+ ssh-copy-id -i ~/.ssh/id_ed25519.pub user@hostname
289
+ ```
290
+
291
+ After setup, SSH/SCP commands authenticate automatically without passwords.
292
+
293
+ **Tip: File Transfer with SCP**
294
+
295
+ Copy files between local and remote servers:
296
+
297
+ ```bash
298
+ # Remote to local
299
+ scp user@hostname:/remote/path/file.txt .
300
+
301
+ # Local to remote
302
+ scp file.txt user@hostname:/remote/path/
303
+
304
+ # Copy directory recursively
305
+ scp -r user@hostname:/remote/folder ./local/
306
+ ```
307
+
308
+ ## Log Files
309
+
310
+ Logs are stored on the remote server in `~/tmux_ssh_logs/`:
311
+
312
+ ```
313
+ ~/tmux_ssh_logs/
314
+ ├── remote_task_20260120_100000.log # Timestamped log
315
+ ├── remote_task_20260120_143022.log # Another run
316
+ ├── remote_task_latest.log # Symlink to latest
317
+ ├── remote_task.lock # Lock file (while running)
318
+ └── task_a1b2c3d4_20260120_110000.log # Log from --new session
319
+ ```
320
+
321
+ The lock file contains information about the running command:
322
+ ```
323
+ cmd: spectre simulation.scs
324
+ started: Mon Jan 20 10:00:00 UTC 2026
325
+ session: remote_task
326
+ log: ~/tmux_ssh_logs/remote_task_20260120_100000.log
327
+ ```
328
+
329
+ ## Command Line Options
330
+
331
+ | Option | Description |
332
+ |--------|-------------|
333
+ | `-H, --host` | Remote hostname |
334
+ | `-U, --user` | Remote username |
335
+ | `-p, --port` | SSH port (default: 22) |
336
+ | `-t, --timeout` | Max seconds to stream (default: unlimited) |
337
+ | `-i, --idle-timeout` | Exit if no output for N seconds (default: 3600) |
338
+ | `-n, --new` | Create a new unique tmux session (inherits cwd, auto-terminates) |
339
+ | `-f, --force` | Force execution, kill any running command |
340
+ | `-k, --kill [SESSION]` | Kill running command (auto-detect if not specified) |
341
+ | `-y, --yes` | Skip confirmation prompt (for --kill) |
342
+ | `-a, --attach [SESSION]` | Attach to session (auto-detect if not specified) |
343
+ | `-l, --list` | List all running commands/sessions |
344
+ | `--cleanup` | Clean up idle task_* sessions (keeps remote_task) |
345
+ | `--auto` | Auto-create new session if command already running (default: true) |
346
+ | `--no-auto` | Disable auto-create, block if command already running |
347
+ | `-C, --clear` | Clear stored credentials |
348
+
349
+ ## Exit Codes
350
+
351
+ | Code | Meaning |
352
+ |------|---------|
353
+ | 0 | Command completed successfully |
354
+ | 1 | Connection or execution error |
355
+ | 2 | Timeout reached, command still running |
356
+ | 3 | Blocked by running command |
357
+
358
+ ## FAQ
359
+
360
+ ### Will closing my laptop or losing internet kill my remote task?
361
+
362
+ **No.** Your remote command continues running safely in the tmux session on the server.
363
+
364
+ ```
365
+ ┌─────────────────┐ ┌─────────────────────────────────────┐
366
+ │ Your Laptop │ SSH │ Remote Server │
367
+ │ │ ──────► │ │
368
+ │ tmux4ssh │ │ tmux session (remote_task) │
369
+ │ (streaming │ ◄────── │ └── your command running │
370
+ │ output only) │ tail │ └── output → log file │
371
+ └─────────────────┘ └─────────────────────────────────────┘
372
+ ```
373
+
374
+ When you close your laptop or lose connection:
375
+ 1. The SSH connection drops
376
+ 2. The local `tmux4ssh` process terminates
377
+ 3. **The remote command keeps running** inside the tmux session
378
+ 4. Output continues to be written to the log file
379
+
380
+ When you reconnect later, use `tmux4ssh --attach` to resume streaming.
381
+
382
+ ### What happens if I press Ctrl+C locally?
383
+
384
+ **Ctrl+C only stops the local streaming process.** The remote command continues running.
385
+
386
+ This is safe and expected behavior — you can press Ctrl+C anytime to stop watching the output without affecting the remote task. To resume streaming later:
387
+
388
+ ```bash
389
+ tmux4ssh --attach
390
+ ```
391
+
392
+ ### How do I actually terminate a running remote command?
393
+
394
+ Use the `--kill` option:
395
+
396
+ ```bash
397
+ # Kill command in auto-detected session
398
+ tmux4ssh --kill
399
+
400
+ # Kill command in a specific session
401
+ tmux4ssh --kill task_a1b2c3d4
402
+ ```
403
+
404
+ Alternative options:
405
+
406
+ ```bash
407
+ # Use --force to kill and run a new command
408
+ tmux4ssh --force "new_command"
409
+
410
+ # SSH directly and kill the process
411
+ ssh user@host
412
+ pkill -f "your_command_pattern"
413
+
414
+ # SSH directly and attach to tmux, then Ctrl+C
415
+ ssh user@host
416
+ tmux attach -t remote_task
417
+ # Now Ctrl+C will kill the command inside tmux
418
+ ```
419
+
420
+ ## Development
421
+
422
+ ### Running Tests
423
+
424
+ ```bash
425
+ # Run all tests (unit tests only by default)
426
+ pytest
427
+
428
+ # Run unit tests only
429
+ pytest -m unit
430
+
431
+ # Run integration tests (requires live SSH connection)
432
+ pytest -m integration
433
+
434
+ # Run with coverage report
435
+ pytest --cov=tmux_ssh --cov-report=html
436
+ ```
437
+
438
+ ### Code Quality
439
+
440
+ ```bash
441
+ # Run linter
442
+ ruff check src tests
443
+
444
+ # Run type checker
445
+ mypy src tests
446
+
447
+ # Run all pre-commit hooks
448
+ pre-commit run --all-files
449
+ ```
450
+
451
+ ## Project Structure
452
+
453
+ ```
454
+ tmux_ssh/
455
+ ├── src/
456
+ │ └── tmux_ssh/
457
+ │ ├── __init__.py
458
+ │ ├── client.py # Main TmuxSSHClient class
459
+ │ └── cli.py # Command-line interface
460
+ ├── tests/
461
+ │ ├── conftest.py # Test fixtures
462
+ │ ├── test_unit.py # Unit tests (mocked)
463
+ │ └── test_integration.py # Integration tests (live SSH)
464
+ ├── pyproject.toml
465
+ ├── .pre-commit-config.yaml
466
+ └── README.md
467
+ ```
468
+
469
+ ## License
470
+
471
+ Apache 2.0
472
+
473
+ ---
474
+
475
+ *Spectre® is a registered trademark of Cadence Design Systems, Inc. All other trademarks are the property of their respective owners.*