agent-pty 0.7.1__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.
- agent_pty-0.7.1/LICENSE +21 -0
- agent_pty-0.7.1/PKG-INFO +212 -0
- agent_pty-0.7.1/README.md +184 -0
- agent_pty-0.7.1/pyproject.toml +80 -0
- agent_pty-0.7.1/pyproject.toml.orig +52 -0
- agent_pty-0.7.1/src/agent_pty/__init__.py +7 -0
- agent_pty-0.7.1/src/agent_pty/main.py +590 -0
- agent_pty-0.7.1/src/agent_pty/py.typed +0 -0
- agent_pty-0.7.1/src/agent_pty/session.py +1386 -0
agent_pty-0.7.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsient
|
|
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.
|
agent_pty-0.7.1/PKG-INFO
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-pty
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: SSH with persistent background PTY sessions, port forwarding, file transfer, and audit logging
|
|
5
|
+
Keywords: ssh,pty,terminal,remote,automation,port-forwarding
|
|
6
|
+
Author: dsient
|
|
7
|
+
Author-email: dsient <dsient@users.noreply.github.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: POSIX
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: System :: Systems Administration
|
|
20
|
+
Classifier: Topic :: Terminals
|
|
21
|
+
Requires-Dist: click>=8.5.1
|
|
22
|
+
Requires-Dist: paramiko>=5.1.0
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Project-URL: Homepage, https://github.com/D5-Interactive/agent-pty
|
|
25
|
+
Project-URL: Repository, https://github.com/D5-Interactive/agent-pty
|
|
26
|
+
Project-URL: Issues, https://github.com/D5-Interactive/agent-pty/issues
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# agent-pty
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/agent-pty/)
|
|
32
|
+
|
|
33
|
+
Persistent SSH sessions with a full interactive PTY, held open in the background.
|
|
34
|
+
|
|
35
|
+
Open a session once. Then run commands, attach to the live shell, forward ports,
|
|
36
|
+
or move files from separate terminal invocations. Commands share one shell, so
|
|
37
|
+
`cd`, exports and functions persist between them. The session survives until you
|
|
38
|
+
close it or its idle TTL expires.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv tool install agent-pty # from PyPI
|
|
44
|
+
uv tool install --from . agent-pty # local checkout
|
|
45
|
+
uv sync && uv run agent-pty --help # development
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Package page: https://pypi.org/project/agent-pty/
|
|
49
|
+
|
|
50
|
+
Python 3.11 or newer.
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 1. open a background session. HOST resolves through ~/.ssh/config
|
|
56
|
+
agent-pty connect web --name web --ttl 30
|
|
57
|
+
|
|
58
|
+
# 2. use it from anywhere
|
|
59
|
+
agent-pty exec -s web 'cd /srv/app && git pull'
|
|
60
|
+
agent-pty exec -s web 'pwd' # /srv/app, state kept
|
|
61
|
+
agent-pty shell -s web # full PTY, Ctrl-] detaches
|
|
62
|
+
agent-pty logs -s web -n 50 # PTY transcript
|
|
63
|
+
agent-pty forward -s web -L 8080:localhost:80 # local tunnel to the remote port
|
|
64
|
+
agent-pty forward -s web -D 1080 # SOCKS5 proxy through the session
|
|
65
|
+
agent-pty connect web -J bastion # reach web through a jump host
|
|
66
|
+
agent-pty upload ./build.tar.gz '~/releases/'
|
|
67
|
+
agent-pty sessions
|
|
68
|
+
agent-pty close -s web
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`-s` accepts a session id, its name, or a unique id prefix. It can be omitted
|
|
72
|
+
when exactly one session is live.
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
| Command | Purpose |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `connect HOST` | Open a background session with an interactive PTY. |
|
|
79
|
+
| `sessions` | List live sessions: id, name, target, pid, idle, start, TTL. |
|
|
80
|
+
| `info` | Show one session: host, user, shell, idle, uptime, TTL, connected, running, forwards, transcript. |
|
|
81
|
+
| `exec CMD...` | Run a command inside the live PTY shell. State persists across calls. |
|
|
82
|
+
| `shell` | Attach to the live PTY. `Ctrl-]` detaches without closing the session. |
|
|
83
|
+
| `send TEXT` | Type text into the live PTY shell. |
|
|
84
|
+
| `interrupt` | Send Ctrl-C, and stop a running `exec` with exit code 130. |
|
|
85
|
+
| `logs` | Print the session transcript, with `-f` to follow it. |
|
|
86
|
+
| `rename NEWNAME` | Give the session a new name. |
|
|
87
|
+
| `forward` | Add, list, or remove SSH port forwards, including a SOCKS5 proxy. |
|
|
88
|
+
| `upload FILE [REMOTE]` | Upload one file. A trailing `/` on REMOTE means that directory. |
|
|
89
|
+
| `upload-dir DIR [REMOTE]` | Upload a directory tree. |
|
|
90
|
+
| `download FILE [LOCAL]` | Download one file. A trailing `/` on LOCAL means that directory. |
|
|
91
|
+
| `download-dir DIR [LOCAL]` | Download a directory tree. |
|
|
92
|
+
| `close` | Close a session and its SSH connection. `--all` closes every session. |
|
|
93
|
+
| `prune` | Delete files left by closed or crashed sessions. |
|
|
94
|
+
|
|
95
|
+
## Flags
|
|
96
|
+
|
|
97
|
+
| Flag | Commands | Meaning |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `-p, --port` | `connect` | SSH port. Default 22 or `~/.ssh/config`. |
|
|
100
|
+
| `-u, --user` | `connect` | Remote user. Default from `~/.ssh/config`, `$USER`, or `root`. |
|
|
101
|
+
| `-i, --key-file` | `connect` | Private key file. Default from `~/.ssh/config` IdentityFile. |
|
|
102
|
+
| `--password` | `connect` | SSH password. Prompted when neither password nor key is given. |
|
|
103
|
+
| `--ttl` | `connect` | Idle timeout in minutes, default 30. |
|
|
104
|
+
| `-n, --name` | `connect` | Friendly session name, usable with `-s`. |
|
|
105
|
+
| `--insecure` | `connect` | Do not verify or record host keys. |
|
|
106
|
+
| `--agent / --no-agent` | `connect` | Use ssh-agent keys, on by default. |
|
|
107
|
+
| `-J, --jump` | `connect` | `[USER@]HOST[:PORT]`, repeatable for a chain. |
|
|
108
|
+
| `--jump-password` | `connect` | Password for a jump host, repeatable in `-J` order. |
|
|
109
|
+
| `--forward-agent` | `connect` | Forward the local ssh-agent to the remote side. |
|
|
110
|
+
| `--reconnect` | `connect` | Reconnect attempts after a dropped connection, default 0. |
|
|
111
|
+
| `--connect-timeout` | `connect` | SSH connect timeout in seconds, default 20. |
|
|
112
|
+
| `--keepalive` | `connect` | SSH keepalive interval in seconds, default 30, 0 disables. |
|
|
113
|
+
| `-s, --session` | most commands | Session id, name, or unique id prefix. |
|
|
114
|
+
| `--timeout` | `exec` | Seconds to wait, default 120. On expiry the command is interrupted and agent-pty exits 124. |
|
|
115
|
+
| `--no-newline` | `send` | Type the text without a trailing newline. |
|
|
116
|
+
| `-n, --lines` | `logs` | Lines to print, default 40. |
|
|
117
|
+
| `-f, --follow` | `logs` | Keep printing new output until Ctrl-C. |
|
|
118
|
+
| `--raw` | `logs` | Keep terminal escape sequences. |
|
|
119
|
+
| `-L, --local` | `forward` | `[BIND:]PORT:HOST:PORT`, listen locally. Repeatable. |
|
|
120
|
+
| `-R, --remote` | `forward` | `[BIND:]PORT:HOST:PORT`, listen on the remote side. Repeatable. |
|
|
121
|
+
| `-D, --dynamic` | `forward` | `[BIND:]PORT`, listen locally as a SOCKS5 proxy. Repeatable. |
|
|
122
|
+
| `--list` | `forward` | Show active forwards. |
|
|
123
|
+
| `--remove ID` | `forward` | Remove a forward by id. |
|
|
124
|
+
| `--json` | `sessions`, `info` | Machine-readable output. |
|
|
125
|
+
| `--all` | `close` | Close every live session. |
|
|
126
|
+
| `-h, --help` | anywhere | Full help, including every subcommand and flag. |
|
|
127
|
+
|
|
128
|
+
## Port forwarding
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
agent-pty forward -s web -L 8080:localhost:80 # local 8080 -> web's port 80
|
|
132
|
+
agent-pty forward -s web -L 15432:db:5432 # local 15432 -> web -> db:5432
|
|
133
|
+
agent-pty forward -s web -R 9000:localhost:3000 # web's 9000 -> your 3000
|
|
134
|
+
agent-pty forward -s web -D 1080 # SOCKS5, resolves from the remote side
|
|
135
|
+
agent-pty forward -s web --list
|
|
136
|
+
agent-pty forward -s web --remove 1
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
For `-L` and `-D`, `HOST:PORT` is resolved on the remote side. For `-R`, it is
|
|
140
|
+
resolved on your side. All default to binding `127.0.0.1`. IPv6 literals use
|
|
141
|
+
brackets, for example `-L [::1]:8080:localhost:80`.
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
curl --socks5-hostname 127.0.0.1:1080 http://internal.service/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Behavior
|
|
148
|
+
|
|
149
|
+
- One daemon process per session, under `~/.agent-pty/sessions/` (mode 0700).
|
|
150
|
+
The daemon dies with its session.
|
|
151
|
+
- `HOST` resolves through `~/.ssh/config` for HostName, User, Port and the first
|
|
152
|
+
IdentityFile.
|
|
153
|
+
- `exec` sends one compound command to the interactive shell and brackets it
|
|
154
|
+
with control-byte markers, so prompts, echoed input and shell hooks stay out
|
|
155
|
+
of the captured output. Since a PTY merges streams, stderr appears with
|
|
156
|
+
stdout. The remote exit code becomes agent-pty's exit code.
|
|
157
|
+
- `exec` and `shell` are mutually exclusive on one session: attaching while a
|
|
158
|
+
command runs is refused, and vice versa.
|
|
159
|
+
- `shell` is a real PTY. Window size is applied on attach and followed on every
|
|
160
|
+
resize.
|
|
161
|
+
- Host keys use trust on first use: keys come from `~/.ssh/known_hosts` and
|
|
162
|
+
`~/.agent-pty/known_hosts`. A changed key fails the connection; remove the
|
|
163
|
+
stale entry there after a legitimate rotation. `--insecure` skips this.
|
|
164
|
+
- The full PTY stream is appended to `~/.agent-pty/sessions/<id>.out` and read
|
|
165
|
+
by `logs`.
|
|
166
|
+
- Every operation is appended to `~/.agent-pty/audit.jsonl`: timestamp,
|
|
167
|
+
session id, action, command, exit code, transfer paths, forwards. Passwords
|
|
168
|
+
are never written there.
|
|
169
|
+
- Jump hosts are honoured from `-J`, or from `ProxyJump` in `~/.ssh/config`.
|
|
170
|
+
Chains of any length work, and each hop uses its own ssh config or SSH agent.
|
|
171
|
+
- `--forward-agent` requests agent forwarding before the shell starts, so the
|
|
172
|
+
remote shell gets `SSH_AUTH_SOCK`. It needs `SSH_AUTH_SOCK` locally.
|
|
173
|
+
- `--reconnect N` retries a dropped connection with backoff. With a zsh or bash
|
|
174
|
+
login shell it also restores exported variables, aliases and functions, plus
|
|
175
|
+
the last working directory, and re-creates port forwards. Running processes
|
|
176
|
+
and history are not restored. Other shells get the directory and forwards.
|
|
177
|
+
- Reconnect state is captured after each `exec`, which adds a small delay per
|
|
178
|
+
command. Sessions without `--reconnect` skip the capture.
|
|
179
|
+
- Each `--jump-password` applies to the matching `-J` hop; pass one per hop, or
|
|
180
|
+
none to use ssh config keys or the agent.
|
|
181
|
+
- The idle TTL closes abandoned sessions and their forwards.
|
|
182
|
+
- Remote `~` is expanded for `upload` and `download` targets.
|
|
183
|
+
- `upload` creates missing remote parent directories and copies directories
|
|
184
|
+
without needing `upload-dir`. Symlinked directories are skipped to avoid loops.
|
|
185
|
+
- `download` detects a remote directory and copies the tree without needing
|
|
186
|
+
`download-dir`.
|
|
187
|
+
- `sessions --json` adds live fields: idle, uptime, attached, running and
|
|
188
|
+
forwards. `logs -f` stops when the session ends.
|
|
189
|
+
- `exec` framing expects a POSIX shell (bash, zsh or sh).
|
|
190
|
+
- `info` reports the detected shell and the size of the captured reconnect state.
|
|
191
|
+
|
|
192
|
+
## Layout
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
src/agent_pty/main.py CLI and client transport
|
|
196
|
+
src/agent_pty/session.py SSH session, PTY pump, exec framing, forwarding, daemon
|
|
197
|
+
tests/test_cli.py help surface, exec framing, forwards, transcript cleaning
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Releases
|
|
201
|
+
|
|
202
|
+
Publishing a GitHub release runs the Publish workflow, which builds the wheel and
|
|
203
|
+
sdist and uploads them to PyPI with the `PYPI_TOKEN` repository secret. A manual
|
|
204
|
+
run is available from the Actions tab.
|
|
205
|
+
|
|
206
|
+
## Development
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
uv sync --all-groups
|
|
210
|
+
uv run ruff check . && uv run ruff format --check .
|
|
211
|
+
uv run pytest -q
|
|
212
|
+
```
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# agent-pty
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/agent-pty/)
|
|
4
|
+
|
|
5
|
+
Persistent SSH sessions with a full interactive PTY, held open in the background.
|
|
6
|
+
|
|
7
|
+
Open a session once. Then run commands, attach to the live shell, forward ports,
|
|
8
|
+
or move files from separate terminal invocations. Commands share one shell, so
|
|
9
|
+
`cd`, exports and functions persist between them. The session survives until you
|
|
10
|
+
close it or its idle TTL expires.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
uv tool install agent-pty # from PyPI
|
|
16
|
+
uv tool install --from . agent-pty # local checkout
|
|
17
|
+
uv sync && uv run agent-pty --help # development
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Package page: https://pypi.org/project/agent-pty/
|
|
21
|
+
|
|
22
|
+
Python 3.11 or newer.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. open a background session. HOST resolves through ~/.ssh/config
|
|
28
|
+
agent-pty connect web --name web --ttl 30
|
|
29
|
+
|
|
30
|
+
# 2. use it from anywhere
|
|
31
|
+
agent-pty exec -s web 'cd /srv/app && git pull'
|
|
32
|
+
agent-pty exec -s web 'pwd' # /srv/app, state kept
|
|
33
|
+
agent-pty shell -s web # full PTY, Ctrl-] detaches
|
|
34
|
+
agent-pty logs -s web -n 50 # PTY transcript
|
|
35
|
+
agent-pty forward -s web -L 8080:localhost:80 # local tunnel to the remote port
|
|
36
|
+
agent-pty forward -s web -D 1080 # SOCKS5 proxy through the session
|
|
37
|
+
agent-pty connect web -J bastion # reach web through a jump host
|
|
38
|
+
agent-pty upload ./build.tar.gz '~/releases/'
|
|
39
|
+
agent-pty sessions
|
|
40
|
+
agent-pty close -s web
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`-s` accepts a session id, its name, or a unique id prefix. It can be omitted
|
|
44
|
+
when exactly one session is live.
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
47
|
+
|
|
48
|
+
| Command | Purpose |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `connect HOST` | Open a background session with an interactive PTY. |
|
|
51
|
+
| `sessions` | List live sessions: id, name, target, pid, idle, start, TTL. |
|
|
52
|
+
| `info` | Show one session: host, user, shell, idle, uptime, TTL, connected, running, forwards, transcript. |
|
|
53
|
+
| `exec CMD...` | Run a command inside the live PTY shell. State persists across calls. |
|
|
54
|
+
| `shell` | Attach to the live PTY. `Ctrl-]` detaches without closing the session. |
|
|
55
|
+
| `send TEXT` | Type text into the live PTY shell. |
|
|
56
|
+
| `interrupt` | Send Ctrl-C, and stop a running `exec` with exit code 130. |
|
|
57
|
+
| `logs` | Print the session transcript, with `-f` to follow it. |
|
|
58
|
+
| `rename NEWNAME` | Give the session a new name. |
|
|
59
|
+
| `forward` | Add, list, or remove SSH port forwards, including a SOCKS5 proxy. |
|
|
60
|
+
| `upload FILE [REMOTE]` | Upload one file. A trailing `/` on REMOTE means that directory. |
|
|
61
|
+
| `upload-dir DIR [REMOTE]` | Upload a directory tree. |
|
|
62
|
+
| `download FILE [LOCAL]` | Download one file. A trailing `/` on LOCAL means that directory. |
|
|
63
|
+
| `download-dir DIR [LOCAL]` | Download a directory tree. |
|
|
64
|
+
| `close` | Close a session and its SSH connection. `--all` closes every session. |
|
|
65
|
+
| `prune` | Delete files left by closed or crashed sessions. |
|
|
66
|
+
|
|
67
|
+
## Flags
|
|
68
|
+
|
|
69
|
+
| Flag | Commands | Meaning |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `-p, --port` | `connect` | SSH port. Default 22 or `~/.ssh/config`. |
|
|
72
|
+
| `-u, --user` | `connect` | Remote user. Default from `~/.ssh/config`, `$USER`, or `root`. |
|
|
73
|
+
| `-i, --key-file` | `connect` | Private key file. Default from `~/.ssh/config` IdentityFile. |
|
|
74
|
+
| `--password` | `connect` | SSH password. Prompted when neither password nor key is given. |
|
|
75
|
+
| `--ttl` | `connect` | Idle timeout in minutes, default 30. |
|
|
76
|
+
| `-n, --name` | `connect` | Friendly session name, usable with `-s`. |
|
|
77
|
+
| `--insecure` | `connect` | Do not verify or record host keys. |
|
|
78
|
+
| `--agent / --no-agent` | `connect` | Use ssh-agent keys, on by default. |
|
|
79
|
+
| `-J, --jump` | `connect` | `[USER@]HOST[:PORT]`, repeatable for a chain. |
|
|
80
|
+
| `--jump-password` | `connect` | Password for a jump host, repeatable in `-J` order. |
|
|
81
|
+
| `--forward-agent` | `connect` | Forward the local ssh-agent to the remote side. |
|
|
82
|
+
| `--reconnect` | `connect` | Reconnect attempts after a dropped connection, default 0. |
|
|
83
|
+
| `--connect-timeout` | `connect` | SSH connect timeout in seconds, default 20. |
|
|
84
|
+
| `--keepalive` | `connect` | SSH keepalive interval in seconds, default 30, 0 disables. |
|
|
85
|
+
| `-s, --session` | most commands | Session id, name, or unique id prefix. |
|
|
86
|
+
| `--timeout` | `exec` | Seconds to wait, default 120. On expiry the command is interrupted and agent-pty exits 124. |
|
|
87
|
+
| `--no-newline` | `send` | Type the text without a trailing newline. |
|
|
88
|
+
| `-n, --lines` | `logs` | Lines to print, default 40. |
|
|
89
|
+
| `-f, --follow` | `logs` | Keep printing new output until Ctrl-C. |
|
|
90
|
+
| `--raw` | `logs` | Keep terminal escape sequences. |
|
|
91
|
+
| `-L, --local` | `forward` | `[BIND:]PORT:HOST:PORT`, listen locally. Repeatable. |
|
|
92
|
+
| `-R, --remote` | `forward` | `[BIND:]PORT:HOST:PORT`, listen on the remote side. Repeatable. |
|
|
93
|
+
| `-D, --dynamic` | `forward` | `[BIND:]PORT`, listen locally as a SOCKS5 proxy. Repeatable. |
|
|
94
|
+
| `--list` | `forward` | Show active forwards. |
|
|
95
|
+
| `--remove ID` | `forward` | Remove a forward by id. |
|
|
96
|
+
| `--json` | `sessions`, `info` | Machine-readable output. |
|
|
97
|
+
| `--all` | `close` | Close every live session. |
|
|
98
|
+
| `-h, --help` | anywhere | Full help, including every subcommand and flag. |
|
|
99
|
+
|
|
100
|
+
## Port forwarding
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
agent-pty forward -s web -L 8080:localhost:80 # local 8080 -> web's port 80
|
|
104
|
+
agent-pty forward -s web -L 15432:db:5432 # local 15432 -> web -> db:5432
|
|
105
|
+
agent-pty forward -s web -R 9000:localhost:3000 # web's 9000 -> your 3000
|
|
106
|
+
agent-pty forward -s web -D 1080 # SOCKS5, resolves from the remote side
|
|
107
|
+
agent-pty forward -s web --list
|
|
108
|
+
agent-pty forward -s web --remove 1
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
For `-L` and `-D`, `HOST:PORT` is resolved on the remote side. For `-R`, it is
|
|
112
|
+
resolved on your side. All default to binding `127.0.0.1`. IPv6 literals use
|
|
113
|
+
brackets, for example `-L [::1]:8080:localhost:80`.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
curl --socks5-hostname 127.0.0.1:1080 http://internal.service/
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Behavior
|
|
120
|
+
|
|
121
|
+
- One daemon process per session, under `~/.agent-pty/sessions/` (mode 0700).
|
|
122
|
+
The daemon dies with its session.
|
|
123
|
+
- `HOST` resolves through `~/.ssh/config` for HostName, User, Port and the first
|
|
124
|
+
IdentityFile.
|
|
125
|
+
- `exec` sends one compound command to the interactive shell and brackets it
|
|
126
|
+
with control-byte markers, so prompts, echoed input and shell hooks stay out
|
|
127
|
+
of the captured output. Since a PTY merges streams, stderr appears with
|
|
128
|
+
stdout. The remote exit code becomes agent-pty's exit code.
|
|
129
|
+
- `exec` and `shell` are mutually exclusive on one session: attaching while a
|
|
130
|
+
command runs is refused, and vice versa.
|
|
131
|
+
- `shell` is a real PTY. Window size is applied on attach and followed on every
|
|
132
|
+
resize.
|
|
133
|
+
- Host keys use trust on first use: keys come from `~/.ssh/known_hosts` and
|
|
134
|
+
`~/.agent-pty/known_hosts`. A changed key fails the connection; remove the
|
|
135
|
+
stale entry there after a legitimate rotation. `--insecure` skips this.
|
|
136
|
+
- The full PTY stream is appended to `~/.agent-pty/sessions/<id>.out` and read
|
|
137
|
+
by `logs`.
|
|
138
|
+
- Every operation is appended to `~/.agent-pty/audit.jsonl`: timestamp,
|
|
139
|
+
session id, action, command, exit code, transfer paths, forwards. Passwords
|
|
140
|
+
are never written there.
|
|
141
|
+
- Jump hosts are honoured from `-J`, or from `ProxyJump` in `~/.ssh/config`.
|
|
142
|
+
Chains of any length work, and each hop uses its own ssh config or SSH agent.
|
|
143
|
+
- `--forward-agent` requests agent forwarding before the shell starts, so the
|
|
144
|
+
remote shell gets `SSH_AUTH_SOCK`. It needs `SSH_AUTH_SOCK` locally.
|
|
145
|
+
- `--reconnect N` retries a dropped connection with backoff. With a zsh or bash
|
|
146
|
+
login shell it also restores exported variables, aliases and functions, plus
|
|
147
|
+
the last working directory, and re-creates port forwards. Running processes
|
|
148
|
+
and history are not restored. Other shells get the directory and forwards.
|
|
149
|
+
- Reconnect state is captured after each `exec`, which adds a small delay per
|
|
150
|
+
command. Sessions without `--reconnect` skip the capture.
|
|
151
|
+
- Each `--jump-password` applies to the matching `-J` hop; pass one per hop, or
|
|
152
|
+
none to use ssh config keys or the agent.
|
|
153
|
+
- The idle TTL closes abandoned sessions and their forwards.
|
|
154
|
+
- Remote `~` is expanded for `upload` and `download` targets.
|
|
155
|
+
- `upload` creates missing remote parent directories and copies directories
|
|
156
|
+
without needing `upload-dir`. Symlinked directories are skipped to avoid loops.
|
|
157
|
+
- `download` detects a remote directory and copies the tree without needing
|
|
158
|
+
`download-dir`.
|
|
159
|
+
- `sessions --json` adds live fields: idle, uptime, attached, running and
|
|
160
|
+
forwards. `logs -f` stops when the session ends.
|
|
161
|
+
- `exec` framing expects a POSIX shell (bash, zsh or sh).
|
|
162
|
+
- `info` reports the detected shell and the size of the captured reconnect state.
|
|
163
|
+
|
|
164
|
+
## Layout
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
src/agent_pty/main.py CLI and client transport
|
|
168
|
+
src/agent_pty/session.py SSH session, PTY pump, exec framing, forwarding, daemon
|
|
169
|
+
tests/test_cli.py help surface, exec framing, forwards, transcript cleaning
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Releases
|
|
173
|
+
|
|
174
|
+
Publishing a GitHub release runs the Publish workflow, which builds the wheel and
|
|
175
|
+
sdist and uploads them to PyPI with the `PYPI_TOKEN` repository secret. A manual
|
|
176
|
+
run is available from the Actions tab.
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
uv sync --all-groups
|
|
182
|
+
uv run ruff check . && uv run ruff format --check .
|
|
183
|
+
uv run pytest -q
|
|
184
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "agent-pty"
|
|
3
|
+
version = "0.7.1"
|
|
4
|
+
description = "SSH with persistent background PTY sessions, port forwarding, file transfer, and audit logging"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
keywords = [
|
|
9
|
+
"ssh",
|
|
10
|
+
"pty",
|
|
11
|
+
"terminal",
|
|
12
|
+
"remote",
|
|
13
|
+
"automation",
|
|
14
|
+
"port-forwarding",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Intended Audience :: System Administrators",
|
|
21
|
+
"Operating System :: POSIX",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: System :: Systems Administration",
|
|
27
|
+
"Topic :: Terminals",
|
|
28
|
+
]
|
|
29
|
+
requires-python = ">=3.11"
|
|
30
|
+
dependencies = [
|
|
31
|
+
"click>=8.5.1",
|
|
32
|
+
"paramiko>=5.1.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[[project.authors]]
|
|
36
|
+
name = "dsient"
|
|
37
|
+
email = "dsient@users.noreply.github.com"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/D5-Interactive/agent-pty"
|
|
41
|
+
Repository = "https://github.com/D5-Interactive/agent-pty"
|
|
42
|
+
Issues = "https://github.com/D5-Interactive/agent-pty/issues"
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
agent-pty = "agent_pty:main"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
dev = [
|
|
49
|
+
"build>=1.6.1",
|
|
50
|
+
"pytest>=8.0",
|
|
51
|
+
"ruff>=0.17",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[build-system]
|
|
55
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
56
|
+
build-backend = "uv_build"
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 120
|
|
60
|
+
target-version = "py311"
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
select = [
|
|
64
|
+
"E",
|
|
65
|
+
"F",
|
|
66
|
+
"I",
|
|
67
|
+
"UP",
|
|
68
|
+
"B",
|
|
69
|
+
"SIM",
|
|
70
|
+
"BLE",
|
|
71
|
+
"S",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint.per-file-ignores]
|
|
75
|
+
"tests/*" = [
|
|
76
|
+
"S101",
|
|
77
|
+
"S104",
|
|
78
|
+
"S106",
|
|
79
|
+
"S108",
|
|
80
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "agent-pty"
|
|
3
|
+
version = "0.7.1"
|
|
4
|
+
description = "SSH with persistent background PTY sessions, port forwarding, file transfer, and audit logging"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "dsient", email = "dsient@users.noreply.github.com" }]
|
|
9
|
+
keywords = ["ssh", "pty", "terminal", "remote", "automation", "port-forwarding"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Intended Audience :: System Administrators",
|
|
15
|
+
"Operating System :: POSIX",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Topic :: System :: Systems Administration",
|
|
21
|
+
"Topic :: Terminals",
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">=3.11"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"click>=8.5.1",
|
|
26
|
+
"paramiko>=5.1.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/D5-Interactive/agent-pty"
|
|
31
|
+
Repository = "https://github.com/D5-Interactive/agent-pty"
|
|
32
|
+
Issues = "https://github.com/D5-Interactive/agent-pty/issues"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
agent-pty = "agent_pty:main"
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
dev = ["build>=1.6.1", "pytest>=8.0", "ruff>=0.17"]
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
42
|
+
build-backend = "uv_build"
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
line-length = 120
|
|
46
|
+
target-version = "py311"
|
|
47
|
+
|
|
48
|
+
[tool.ruff.lint]
|
|
49
|
+
select = ["E", "F", "I", "UP", "B", "SIM", "BLE", "S"]
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint.per-file-ignores]
|
|
52
|
+
"tests/*" = ["S101", "S104", "S106", "S108"]
|