side-cli 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.
side_cli-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GGN_2015
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,262 @@
1
+ Metadata-Version: 2.4
2
+ Name: side-cli
3
+ Version: 0.1.0
4
+ Summary: Supervise a command and bridge its standard streams over local TCP.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+
10
+ # side-cli
11
+
12
+ Run a command with piped standard streams and bridge them to local TCP ports.
13
+ Use the console, the Tk desktop window, or the async Python API. Receive
14
+ stdout and stderr on separate ports or on one framed output port.
15
+
16
+ ## Quick start
17
+
18
+ Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and run
19
+ these commands from the project directory. The project requires Python 3.11
20
+ or later and has no third-party runtime dependencies.
21
+
22
+ ```shell
23
+ uv sync --locked
24
+ uv run side-cli run -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"
25
+ ```
26
+
27
+ Type a line in the terminal, or send it to the stdin TCP port. The example
28
+ prints the line and exits. `side_cli` and `python -m side_cli` are also entry
29
+ points. Put `run` options before `--` and the child command and its arguments
30
+ after it. Run `side-cli run --help` for supervisor options.
31
+ Commands run directly; use an explicit shell for shell syntax, for example
32
+ `-- sh -c "printf 'hello\n'"` on Linux or `-- cmd /c "echo hello"` on Windows.
33
+
34
+ ```shell
35
+ uv run side-cli run --gui -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"
36
+ ```
37
+
38
+ The GUI shows stdout and stderr in the left-hand console. Both use the same
39
+ default colors; ANSI color sequences in each stream control their text colors.
40
+ When the end of the output is visible, a blinking caret marks it without
41
+ changing the text or taking keyboard focus.
42
+ Click the output to focus the input field; selecting output text keeps focus
43
+ in the output so it can be copied.
44
+ On the right, **Send** echoes the text immediately. Uncheck **Append newline**
45
+ to add text to the pending line without writing to the child yet. Send a
46
+ newline to deliver the full line, including the newline, to the child.
47
+ The TCP panel shows each bound address, listening state, and active connection
48
+ count. The window keeps the output visible after the command exits. Closing
49
+ the window stops a command that is still running. GUI mode requires Tkinter
50
+ and a desktop session; run `uv run python -m tkinter` to check. If you use the
51
+ system Python on Debian or Ubuntu, install its `python3-tk` package if needed.
52
+
53
+ ## TCP and process behavior
54
+
55
+ | Stream | Default address | Direction |
56
+ | --- | --- | --- |
57
+ | stdin | `127.0.0.1:8765` | TCP client to child stdin |
58
+ | stdout | `127.0.0.1:8766` | Child stdout to connected TCP clients |
59
+ | stderr | `127.0.0.1:8767` | Child stderr to connected TCP clients |
60
+
61
+ - Configure ports with `--stdin-port`, `--stdout-port`, and `--stderr-port`.
62
+ Use `0` for an available port and `--show-ports` to print the actual addresses.
63
+ Listeners accept unauthenticated connections from the local machine only.
64
+ - The stdin port carries LF-delimited byte frames. Separate output ports
65
+ carry raw bytes. Output goes to clients
66
+ connected at the time of the write, with no replay. To capture output from
67
+ the first byte, use `--wait-for-output-clients` and connect to each enabled
68
+ output port before the child starts. Keep output clients connected in both
69
+ directions until done. A slow client may be disconnected to keep other
70
+ readers moving.
71
+ - Both modes mirror the child's stdout and stderr separately. Console mode
72
+ also forwards terminal or piped stdin, unless you set `--no-local-stdin`.
73
+ The GUI, local stdin, and each input connection buffer their own input
74
+ until a newline. Complete lines from concurrent sources can interleave
75
+ only between lines. On EOF an incomplete line is discarded; stdin stays
76
+ open for other clients unless `--close-stdin-on-eof` is set. Combine that
77
+ option with `--no-local-stdin` for commands that read TCP input until EOF.
78
+ - Input echo is a local display feature. The GUI and the terminal running
79
+ `side-cli run` show submitted GUI and TCP input, even before a newline.
80
+ A terminal keyboard already provides its own echo. Synthetic echo is not
81
+ sent to the child, the TCP output ports, `panel`, or redirected stdout or
82
+ stderr. Output echoed by the child itself is still forwarded normally.
83
+ - Ctrl+C reaches the child as `SIGINT` on Linux. On Windows, the child shares
84
+ the console and receives the native Ctrl+C event directly. A child that
85
+ handles the interrupt can clean up or continue. Console mode returns the
86
+ child's exit code, with POSIX signal exits reported as `128 + signal`.
87
+ - The child gets pipes, not a terminal. For timely output from buffered
88
+ commands, enable their unbuffered mode (such as Python's `-u`). The GUI
89
+ renders ANSI foreground and background colors (basic, bright, 256-color,
90
+ and RGB), but does not emulate cursor movement or screen clearing. If a
91
+ command disables colors when writing to a pipe, use its force-color option.
92
+ - On Windows, when launching `cmd.exe` directly, side-cli removes Clink's
93
+ hidden tag from the child `PROMPT` but preserves the rest of the prompt.
94
+ Clink's interactive editing and completion still require a console.
95
+
96
+ ## Text encoding
97
+
98
+ `--encoding` describes the encoding used by the child process. It defaults to
99
+ `utf-8` and accepts Python text encodings such as `gb2312`, `gbk`, and `cp936`.
100
+ Choose the encoding that matches the command; the option does not change the
101
+ child's locale or code page.
102
+
103
+ ```shell
104
+ uv run side-cli run --gui --encoding gb2312 -- cmd.exe
105
+ uv run side-cli panel --port 8766 --encoding gb2312
106
+ uv run side-cli input --port 8765 --encoding gb2312
107
+ ```
108
+
109
+ `run` converts terminal and GUI text in both directions. `panel` decodes
110
+ output for the terminal, and `input` encodes lines typed at the terminal.
111
+ Redirected files and pipes, TCP payloads, and the byte-oriented Python API
112
+ do not transcode. Byte-framed input uses encodings with an ASCII LF, such as
113
+ UTF-8, GB2312, and GBK. Each client sets its own encoding for terminal display or
114
+ entry; the TCP protocol does not negotiate encodings.
115
+
116
+ ## Single framed output port
117
+
118
+ Set `--output-port` to replace both output TCP listeners with one connection
119
+ point carrying both streams. This option cannot be combined with
120
+ `--stdout-port` or `--stderr-port`. The stdin listener, local output, and GUI
121
+ ANSI rendering keep their existing behavior. The GUI and `--show-ports`
122
+ report one combined output listener; `--wait-for-output-clients` waits for
123
+ one client on it.
124
+
125
+ ```shell
126
+ uv run side-cli run --output-port 8766 --wait-for-output-clients --no-local-stdin -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); sys.stdout.writelines(sys.stdin)"
127
+ ```
128
+
129
+ In a second terminal, connect to the framed output port:
130
+
131
+ ```shell
132
+ uv run side-cli panel --port 8766
133
+ ```
134
+
135
+ `panel` writes frames to its own stdout or stderr according to their stream
136
+ ID. Redirect either stream independently to capture its raw bytes. The child
137
+ still writes to the supervisor's own stdout and stderr too.
138
+
139
+ In a third terminal, send lines to the stdin port:
140
+
141
+ ```shell
142
+ uv run side-cli input --port 8765
143
+ ```
144
+
145
+ `input` writes nothing to stdout and reports connection errors to stderr.
146
+ It forwards complete lines, preserving line endings, and drops any final
147
+ unterminated line at local EOF. Multiple input clients can connect at once.
148
+ Ctrl+C disconnects
149
+ that input client without sending a signal or an orderly EOF to the child.
150
+ An ordinary local EOF disconnects cleanly and leaves child stdin open unless
151
+ the supervisor was started with `--close-stdin-on-eof`. Use separate terminals
152
+ for the supervisor and its clients so Ctrl+C goes to the intended command.
153
+
154
+ ### Frame format
155
+
156
+ The **stdin** connection uses LF (`0x0a`) as the frame delimiter. A frame
157
+ includes its delimiter; CRLF is passed through unchanged. One TCP read may
158
+ contain several frames, and a single frame can span reads. The supervisor
159
+ buffers at most 1 MiB per line, including the delimiter. An oversized line
160
+ closes that input connection. An incomplete line is never written to the child.
161
+
162
+ The combined **output** port uses a separate protocol:
163
+
164
+ The connection carries consecutive binary frames with no initial preamble:
165
+
166
+ | Field | Size | Value |
167
+ | --- | --- | --- |
168
+ | Stream ID | 1 byte | `1` = stdout, `2` = stderr |
169
+ | Payload length | 4 bytes | Unsigned big-endian byte count, 1–65,536 |
170
+ | Payload | As specified above | Raw bytes from the selected stream, including ANSI escapes |
171
+
172
+ Read five bytes for the header, then exactly the specified number of payload
173
+ bytes. Frames represent chunks, not lines, characters, or individual child
174
+ writes. Each stream retains its own byte order. Frames from the two streams
175
+ interleave in the order side-cli reads them. EOF at a frame boundary ends the
176
+ connection; EOF inside a frame indicates truncation.
177
+
178
+ ## Python API
179
+
180
+ Import `Supervisor`, `Ports`, and `Stream` from `side_cli`. An async context
181
+ opens the listeners on entry and releases them on exit. `start()` launches
182
+ the child; `wait()` drains its output and returns its original exit code.
183
+
184
+ ```python
185
+ import asyncio
186
+ import sys
187
+
188
+ from side_cli import Ports, Stream, Supervisor
189
+
190
+
191
+ def show_output(stream: Stream, data: bytes) -> None:
192
+ destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
193
+ destination.buffer.write(data)
194
+ destination.buffer.flush()
195
+
196
+
197
+ async def main() -> int:
198
+ command = [sys.executable, "-u", "-c", "print(input())"]
199
+ async with Supervisor(command, ports=Ports(0, 0, 0), on_output=show_output) as child:
200
+ print(child.status()[Stream.STDIN].port, flush=True)
201
+ await child.start()
202
+ await child.send(b"Hello from Python\n")
203
+ await child.close_stdin()
204
+ return await child.wait()
205
+
206
+
207
+ if __name__ == "__main__":
208
+ raise SystemExit(asyncio.run(main()))
209
+ ```
210
+
211
+ `on_output` can also be an async function. It receives raw chunks in order
212
+ within each stream; stdout and stderr may interleave. `status()` exposes port
213
+ and connection information, including when the child has not started yet.
214
+ `Supervisor.send()` is the low-level raw stdin write for programs that need
215
+ to bypass line framing. To display TCP input separately, supply
216
+ `on_input_echo` with a synchronous or async callback that receives text
217
+ decoded with `input_encoding` (UTF-8 by default).
218
+ Pass `Ports(stdin=0, output=0)` to enable framed mode with automatic ports.
219
+ In this mode, `status()["output"]` reports the combined listener, and
220
+ `on_output` still receives the original `Stream.STDOUT` or `Stream.STDERR`.
221
+ The `stdout` and `stderr` port settings apply only in separate-port mode.
222
+ Call `listen()` directly if you need to bind before starting without a context
223
+ manager, and use `aclose()` to clean up. An embedding app owns its own signal
224
+ handlers. On Windows, use the default asyncio Proactor event loop.
225
+
226
+ ### TCP clients
227
+
228
+ Import `PanelClient` and `InputClient` from `side_cli`. Both connect to the
229
+ local supervisor as async context managers. `PanelClient` yields
230
+ `(Stream.STDOUT, bytes)` or `(Stream.STDERR, bytes)` pairs until the connection
231
+ ends; malformed or truncated frames raise `ValueError`. `InputClient.send()`
232
+ writes bytes unchanged to the TCP connection, and `send_line()` appends an LF
233
+ if one is missing. The supervisor only forwards complete LF-delimited lines.
234
+ Context cancellation aborts the input connection rather than sending an
235
+ orderly EOF. Use `close(abort=True)` for an explicit abort.
236
+
237
+ ```python
238
+ import sys
239
+
240
+ from side_cli import InputClient, PanelClient, Stream
241
+
242
+
243
+ async def receive_output(port: int = 8766) -> None:
244
+ async with PanelClient(port) as panel:
245
+ async for stream, data in panel:
246
+ destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
247
+ destination.buffer.write(data)
248
+ destination.buffer.flush()
249
+
250
+
251
+ async def send_input(port: int = 8765) -> None:
252
+ async with InputClient(port) as client:
253
+ await client.send_line(b"Hello from Python")
254
+ ```
255
+
256
+ ## Build
257
+
258
+ ```shell
259
+ uv build
260
+ ```
261
+
262
+ Released under the [MIT License](LICENSE).
@@ -0,0 +1,253 @@
1
+ # side-cli
2
+
3
+ Run a command with piped standard streams and bridge them to local TCP ports.
4
+ Use the console, the Tk desktop window, or the async Python API. Receive
5
+ stdout and stderr on separate ports or on one framed output port.
6
+
7
+ ## Quick start
8
+
9
+ Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and run
10
+ these commands from the project directory. The project requires Python 3.11
11
+ or later and has no third-party runtime dependencies.
12
+
13
+ ```shell
14
+ uv sync --locked
15
+ uv run side-cli run -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"
16
+ ```
17
+
18
+ Type a line in the terminal, or send it to the stdin TCP port. The example
19
+ prints the line and exits. `side_cli` and `python -m side_cli` are also entry
20
+ points. Put `run` options before `--` and the child command and its arguments
21
+ after it. Run `side-cli run --help` for supervisor options.
22
+ Commands run directly; use an explicit shell for shell syntax, for example
23
+ `-- sh -c "printf 'hello\n'"` on Linux or `-- cmd /c "echo hello"` on Windows.
24
+
25
+ ```shell
26
+ uv run side-cli run --gui -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"
27
+ ```
28
+
29
+ The GUI shows stdout and stderr in the left-hand console. Both use the same
30
+ default colors; ANSI color sequences in each stream control their text colors.
31
+ When the end of the output is visible, a blinking caret marks it without
32
+ changing the text or taking keyboard focus.
33
+ Click the output to focus the input field; selecting output text keeps focus
34
+ in the output so it can be copied.
35
+ On the right, **Send** echoes the text immediately. Uncheck **Append newline**
36
+ to add text to the pending line without writing to the child yet. Send a
37
+ newline to deliver the full line, including the newline, to the child.
38
+ The TCP panel shows each bound address, listening state, and active connection
39
+ count. The window keeps the output visible after the command exits. Closing
40
+ the window stops a command that is still running. GUI mode requires Tkinter
41
+ and a desktop session; run `uv run python -m tkinter` to check. If you use the
42
+ system Python on Debian or Ubuntu, install its `python3-tk` package if needed.
43
+
44
+ ## TCP and process behavior
45
+
46
+ | Stream | Default address | Direction |
47
+ | --- | --- | --- |
48
+ | stdin | `127.0.0.1:8765` | TCP client to child stdin |
49
+ | stdout | `127.0.0.1:8766` | Child stdout to connected TCP clients |
50
+ | stderr | `127.0.0.1:8767` | Child stderr to connected TCP clients |
51
+
52
+ - Configure ports with `--stdin-port`, `--stdout-port`, and `--stderr-port`.
53
+ Use `0` for an available port and `--show-ports` to print the actual addresses.
54
+ Listeners accept unauthenticated connections from the local machine only.
55
+ - The stdin port carries LF-delimited byte frames. Separate output ports
56
+ carry raw bytes. Output goes to clients
57
+ connected at the time of the write, with no replay. To capture output from
58
+ the first byte, use `--wait-for-output-clients` and connect to each enabled
59
+ output port before the child starts. Keep output clients connected in both
60
+ directions until done. A slow client may be disconnected to keep other
61
+ readers moving.
62
+ - Both modes mirror the child's stdout and stderr separately. Console mode
63
+ also forwards terminal or piped stdin, unless you set `--no-local-stdin`.
64
+ The GUI, local stdin, and each input connection buffer their own input
65
+ until a newline. Complete lines from concurrent sources can interleave
66
+ only between lines. On EOF an incomplete line is discarded; stdin stays
67
+ open for other clients unless `--close-stdin-on-eof` is set. Combine that
68
+ option with `--no-local-stdin` for commands that read TCP input until EOF.
69
+ - Input echo is a local display feature. The GUI and the terminal running
70
+ `side-cli run` show submitted GUI and TCP input, even before a newline.
71
+ A terminal keyboard already provides its own echo. Synthetic echo is not
72
+ sent to the child, the TCP output ports, `panel`, or redirected stdout or
73
+ stderr. Output echoed by the child itself is still forwarded normally.
74
+ - Ctrl+C reaches the child as `SIGINT` on Linux. On Windows, the child shares
75
+ the console and receives the native Ctrl+C event directly. A child that
76
+ handles the interrupt can clean up or continue. Console mode returns the
77
+ child's exit code, with POSIX signal exits reported as `128 + signal`.
78
+ - The child gets pipes, not a terminal. For timely output from buffered
79
+ commands, enable their unbuffered mode (such as Python's `-u`). The GUI
80
+ renders ANSI foreground and background colors (basic, bright, 256-color,
81
+ and RGB), but does not emulate cursor movement or screen clearing. If a
82
+ command disables colors when writing to a pipe, use its force-color option.
83
+ - On Windows, when launching `cmd.exe` directly, side-cli removes Clink's
84
+ hidden tag from the child `PROMPT` but preserves the rest of the prompt.
85
+ Clink's interactive editing and completion still require a console.
86
+
87
+ ## Text encoding
88
+
89
+ `--encoding` describes the encoding used by the child process. It defaults to
90
+ `utf-8` and accepts Python text encodings such as `gb2312`, `gbk`, and `cp936`.
91
+ Choose the encoding that matches the command; the option does not change the
92
+ child's locale or code page.
93
+
94
+ ```shell
95
+ uv run side-cli run --gui --encoding gb2312 -- cmd.exe
96
+ uv run side-cli panel --port 8766 --encoding gb2312
97
+ uv run side-cli input --port 8765 --encoding gb2312
98
+ ```
99
+
100
+ `run` converts terminal and GUI text in both directions. `panel` decodes
101
+ output for the terminal, and `input` encodes lines typed at the terminal.
102
+ Redirected files and pipes, TCP payloads, and the byte-oriented Python API
103
+ do not transcode. Byte-framed input uses encodings with an ASCII LF, such as
104
+ UTF-8, GB2312, and GBK. Each client sets its own encoding for terminal display or
105
+ entry; the TCP protocol does not negotiate encodings.
106
+
107
+ ## Single framed output port
108
+
109
+ Set `--output-port` to replace both output TCP listeners with one connection
110
+ point carrying both streams. This option cannot be combined with
111
+ `--stdout-port` or `--stderr-port`. The stdin listener, local output, and GUI
112
+ ANSI rendering keep their existing behavior. The GUI and `--show-ports`
113
+ report one combined output listener; `--wait-for-output-clients` waits for
114
+ one client on it.
115
+
116
+ ```shell
117
+ uv run side-cli run --output-port 8766 --wait-for-output-clients --no-local-stdin -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); sys.stdout.writelines(sys.stdin)"
118
+ ```
119
+
120
+ In a second terminal, connect to the framed output port:
121
+
122
+ ```shell
123
+ uv run side-cli panel --port 8766
124
+ ```
125
+
126
+ `panel` writes frames to its own stdout or stderr according to their stream
127
+ ID. Redirect either stream independently to capture its raw bytes. The child
128
+ still writes to the supervisor's own stdout and stderr too.
129
+
130
+ In a third terminal, send lines to the stdin port:
131
+
132
+ ```shell
133
+ uv run side-cli input --port 8765
134
+ ```
135
+
136
+ `input` writes nothing to stdout and reports connection errors to stderr.
137
+ It forwards complete lines, preserving line endings, and drops any final
138
+ unterminated line at local EOF. Multiple input clients can connect at once.
139
+ Ctrl+C disconnects
140
+ that input client without sending a signal or an orderly EOF to the child.
141
+ An ordinary local EOF disconnects cleanly and leaves child stdin open unless
142
+ the supervisor was started with `--close-stdin-on-eof`. Use separate terminals
143
+ for the supervisor and its clients so Ctrl+C goes to the intended command.
144
+
145
+ ### Frame format
146
+
147
+ The **stdin** connection uses LF (`0x0a`) as the frame delimiter. A frame
148
+ includes its delimiter; CRLF is passed through unchanged. One TCP read may
149
+ contain several frames, and a single frame can span reads. The supervisor
150
+ buffers at most 1 MiB per line, including the delimiter. An oversized line
151
+ closes that input connection. An incomplete line is never written to the child.
152
+
153
+ The combined **output** port uses a separate protocol:
154
+
155
+ The connection carries consecutive binary frames with no initial preamble:
156
+
157
+ | Field | Size | Value |
158
+ | --- | --- | --- |
159
+ | Stream ID | 1 byte | `1` = stdout, `2` = stderr |
160
+ | Payload length | 4 bytes | Unsigned big-endian byte count, 1–65,536 |
161
+ | Payload | As specified above | Raw bytes from the selected stream, including ANSI escapes |
162
+
163
+ Read five bytes for the header, then exactly the specified number of payload
164
+ bytes. Frames represent chunks, not lines, characters, or individual child
165
+ writes. Each stream retains its own byte order. Frames from the two streams
166
+ interleave in the order side-cli reads them. EOF at a frame boundary ends the
167
+ connection; EOF inside a frame indicates truncation.
168
+
169
+ ## Python API
170
+
171
+ Import `Supervisor`, `Ports`, and `Stream` from `side_cli`. An async context
172
+ opens the listeners on entry and releases them on exit. `start()` launches
173
+ the child; `wait()` drains its output and returns its original exit code.
174
+
175
+ ```python
176
+ import asyncio
177
+ import sys
178
+
179
+ from side_cli import Ports, Stream, Supervisor
180
+
181
+
182
+ def show_output(stream: Stream, data: bytes) -> None:
183
+ destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
184
+ destination.buffer.write(data)
185
+ destination.buffer.flush()
186
+
187
+
188
+ async def main() -> int:
189
+ command = [sys.executable, "-u", "-c", "print(input())"]
190
+ async with Supervisor(command, ports=Ports(0, 0, 0), on_output=show_output) as child:
191
+ print(child.status()[Stream.STDIN].port, flush=True)
192
+ await child.start()
193
+ await child.send(b"Hello from Python\n")
194
+ await child.close_stdin()
195
+ return await child.wait()
196
+
197
+
198
+ if __name__ == "__main__":
199
+ raise SystemExit(asyncio.run(main()))
200
+ ```
201
+
202
+ `on_output` can also be an async function. It receives raw chunks in order
203
+ within each stream; stdout and stderr may interleave. `status()` exposes port
204
+ and connection information, including when the child has not started yet.
205
+ `Supervisor.send()` is the low-level raw stdin write for programs that need
206
+ to bypass line framing. To display TCP input separately, supply
207
+ `on_input_echo` with a synchronous or async callback that receives text
208
+ decoded with `input_encoding` (UTF-8 by default).
209
+ Pass `Ports(stdin=0, output=0)` to enable framed mode with automatic ports.
210
+ In this mode, `status()["output"]` reports the combined listener, and
211
+ `on_output` still receives the original `Stream.STDOUT` or `Stream.STDERR`.
212
+ The `stdout` and `stderr` port settings apply only in separate-port mode.
213
+ Call `listen()` directly if you need to bind before starting without a context
214
+ manager, and use `aclose()` to clean up. An embedding app owns its own signal
215
+ handlers. On Windows, use the default asyncio Proactor event loop.
216
+
217
+ ### TCP clients
218
+
219
+ Import `PanelClient` and `InputClient` from `side_cli`. Both connect to the
220
+ local supervisor as async context managers. `PanelClient` yields
221
+ `(Stream.STDOUT, bytes)` or `(Stream.STDERR, bytes)` pairs until the connection
222
+ ends; malformed or truncated frames raise `ValueError`. `InputClient.send()`
223
+ writes bytes unchanged to the TCP connection, and `send_line()` appends an LF
224
+ if one is missing. The supervisor only forwards complete LF-delimited lines.
225
+ Context cancellation aborts the input connection rather than sending an
226
+ orderly EOF. Use `close(abort=True)` for an explicit abort.
227
+
228
+ ```python
229
+ import sys
230
+
231
+ from side_cli import InputClient, PanelClient, Stream
232
+
233
+
234
+ async def receive_output(port: int = 8766) -> None:
235
+ async with PanelClient(port) as panel:
236
+ async for stream, data in panel:
237
+ destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
238
+ destination.buffer.write(data)
239
+ destination.buffer.flush()
240
+
241
+
242
+ async def send_input(port: int = 8765) -> None:
243
+ async with InputClient(port) as client:
244
+ await client.send_line(b"Hello from Python")
245
+ ```
246
+
247
+ ## Build
248
+
249
+ ```shell
250
+ uv build
251
+ ```
252
+
253
+ Released under the [MIT License](LICENSE).
@@ -0,0 +1,17 @@
1
+ [project]
2
+ name = "side-cli"
3
+ version = "0.1.0"
4
+ description = "Supervise a command and bridge its standard streams over local TCP."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ dependencies = []
10
+
11
+ [project.scripts]
12
+ side-cli = "side_cli.cli:main"
13
+ side_cli = "side_cli.cli:main"
14
+
15
+ [build-system]
16
+ requires = ["uv_build>=0.11.0,<0.14.0"]
17
+ build-backend = "uv_build"
@@ -0,0 +1,17 @@
1
+ [project]
2
+ name = "side-cli"
3
+ version = "0.1.0"
4
+ description = "Supervise a command and bridge its standard streams over local TCP."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ dependencies = []
10
+
11
+ [project.scripts]
12
+ side-cli = "side_cli.cli:main"
13
+ side_cli = "side_cli.cli:main"
14
+
15
+ [build-system]
16
+ requires = ["uv_build>=0.11.0,<0.14.0"]
17
+ build-backend = "uv_build"
@@ -0,0 +1,6 @@
1
+ """Public API for supervising a command and bridging its standard streams."""
2
+
3
+ from .clients import InputClient, PanelClient
4
+ from .supervisor import HOST, PortStatus, Ports, Stream, Supervisor
5
+
6
+ __all__ = ["HOST", "InputClient", "PanelClient", "PortStatus", "Ports", "Stream", "Supervisor"]
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())