bgo-cli 0.2.0__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,273 @@
1
+ Metadata-Version: 2.4
2
+ Name: bgo-cli
3
+ Version: 0.2.0
4
+ Summary: Lightweight, zero-dependency background process manager (pm2-style) with watch mode and auto-restart.
5
+ Project-URL: Homepage, https://github.com/tcsenpai/bgo
6
+ Project-URL: Repository, https://github.com/tcsenpai/bgo
7
+ Project-URL: Issues, https://github.com/tcsenpai/bgo/issues
8
+ Project-URL: Changelog, https://github.com/tcsenpai/bgo/commits/main
9
+ Author-email: tcsenpai <tcsenpai@discus.sh>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: background,cli,daemon,pm2,process-manager,supervisor,watchdog
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: Operating System :: MacOS :: MacOS X
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: System :: Systems Administration
27
+ Classifier: Topic :: Utilities
28
+ Requires-Python: >=3.9
29
+ Provides-Extra: dev
30
+ Requires-Dist: build>=1.0; extra == 'dev'
31
+ Requires-Dist: pytest>=7.0; extra == 'dev'
32
+ Requires-Dist: twine>=4.0; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # bgo - Background Go
36
+
37
+ Lightweight, zero-dep background process manager inspired by pm2.
38
+ Detach any binary or script from your shell with one command.
39
+
40
+ ## Features
41
+
42
+ - ๐Ÿš€ **Simple syntax** โ€” `bgo <name> -- <command>`
43
+ - ๐Ÿง **Unix-style aliases** โ€” `bgo open` / `kill` / `rm` / `ls`
44
+ - ๐Ÿ“Š **Status monitoring** โ€” CPU, memory, uptime in plain / normal / fancy tables (auto-detect)
45
+ - ๐Ÿ“ **Log management** โ€” stdout / stderr / watcher logs with follow mode
46
+ - ๐Ÿ”„ **Lifecycle** โ€” start, stop, restart, restart-stopped, restart-last, resurrect
47
+ - ๐Ÿ‘ **Watch mode** โ€” auto-restart crashed processes with fast-crash backoff
48
+ - ๐Ÿงน **Auto-cleanup** โ€” clean stopped procs; keep logs on delete if desired
49
+ - ๐Ÿค– **Scriptable** โ€” `--json` output for any pipeline
50
+ - โšก **Zero runtime dependencies** โ€” pure Python 3.9+
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ # Via PyPI
56
+ pip install bgo-cli
57
+ # or
58
+ pipx install bgo-cli
59
+ # or
60
+ uv tool install bgo-cli
61
+
62
+ # Via the install script (system-wide, needs sudo)
63
+ ./install.sh
64
+
65
+ # User-local (~/.local/bin, no sudo)
66
+ ./install.sh --local
67
+
68
+ # Or manually โ€” bgo is a single file
69
+ cp bgo ~/.local/bin/ # or /usr/local/bin/
70
+ ln -s "$(pwd)/bgo" ~/.local/bin/bgo
71
+ ```
72
+
73
+ Run `./install.sh --help` for `--force` and `--uninstall` options.
74
+
75
+ ## Quick Start
76
+
77
+ ```bash
78
+ # Start a process
79
+ bgo myserver -- python3 -m http.server 8080
80
+ bgo open myserver -- python3 -m http.server 8080 # alias
81
+
82
+ # Check status
83
+ bgo status # full alias chain: status / ls / list
84
+ bgo ls
85
+
86
+ # Status detail for one proc (or: bgo <registered-name>)
87
+ bgo myserver
88
+
89
+ # View logs
90
+ bgo logs myserver
91
+ bgo logs myserver -f # follow (tail -f)
92
+ bgo follow myserver # alias for logs -f
93
+
94
+ # Stop / restart / delete
95
+ bgo stop myserver # or: bgo kill myserver
96
+ bgo restart myserver
97
+ bgo delete myserver # or: bgo rm myserver
98
+ bgo rm myserver --keep-logs # preserve log files
99
+
100
+ # Bare `bgo` prints help; `bgo <unknown>` errors out (never silently spawns)
101
+ bgo
102
+ ```
103
+
104
+ ## Commands
105
+
106
+ ### Lifecycle
107
+
108
+ | Command | Description |
109
+ |---|---|
110
+ | `bgo start <name> -- <cmd>` | Start a process (alias: `open`) |
111
+ | `bgo <name> -- <cmd>` | Shorthand for start |
112
+ | `bgo stop <name>` | Stop (SIGTERM, alias: `kill`) |
113
+ | `bgo stop <name> -f` | Force kill (SIGKILL) |
114
+ | `bgo restart <name>` | Restart; preserves watch state and counters |
115
+ | `bgo restart <name> --reset-counters` | Also zero `watch.restarts` |
116
+ | `bgo restart-stopped` | Pick stopped procs to restart (interactive) |
117
+ | `bgo restart-stopped --all` | Restart every stopped proc |
118
+ | `bgo restart-stopped <name>...` | Restart named stopped procs |
119
+ | `bgo restart-last` | Menu sorted most-recent-first |
120
+ | `bgo restart-last --all` | Restart all not-running procs in recent order |
121
+ | `bgo resurrect` | Restart all procs that were running before shutdown |
122
+ | `bgo delete <name>` | Remove proc + logs (alias: `rm`) |
123
+ | `bgo delete <name> --keep-logs` | Remove proc, keep logs |
124
+ | `bgo clean` | Drop all stopped procs from the list |
125
+
126
+ ### Inspection
127
+
128
+ | Command | Description |
129
+ |---|---|
130
+ | `bgo status` | Process table (alias: `ls`, `list`) |
131
+ | `bgo status <name>` | Detail view for one proc |
132
+ | `bgo status -w` | Watch mode (auto-refresh every 2s) |
133
+ | `bgo status -w --interval N` | Custom refresh interval |
134
+ | `bgo status --json` | Machine-readable output |
135
+ | `bgo status --plain` | ASCII-only output (no color, no glyphs) |
136
+ | `bgo status --fancy` | Force Unicode box-drawing rendering |
137
+ | `bgo <registered-name>` | Shorthand for `bgo status <name>` |
138
+ | `bgo logs <name>` | Last 50 lines |
139
+ | `bgo logs <name> -f` | Follow logs |
140
+ | `bgo logs <name> -n 100` | Last 100 lines |
141
+ | `bgo logs <name> --stderr` | Only stderr |
142
+ | `bgo logs <name> --watcher` | Watcher event log |
143
+ | `bgo follow <name>` | Alias for `logs -f` (also: `tail`) |
144
+
145
+ ### Watch mode
146
+
147
+ | Command | Description |
148
+ |---|---|
149
+ | `bgo start -w <name> -- <cmd>` | Start with watcher attached |
150
+ | `bgo -w <name> <cmd>` | Direct mode with watcher |
151
+ | `bgo watch <name>` | Attach watcher to a running proc |
152
+ | `bgo watch <name> --interval N --min-uptime N --on-fast-crash MODE` | Tune |
153
+ | `bgo unwatch <name>` | Detach watcher, keep proc |
154
+
155
+ ## Examples
156
+
157
+ ```bash
158
+ # Python HTTP server
159
+ bgo web -- python3 -m http.server 8080
160
+
161
+ # Node.js app with watcher
162
+ bgo -w api -- npm start
163
+
164
+ # Custom binary with working directory
165
+ bgo start dashboard --cwd /opt/app -- node server.js
166
+
167
+ # Inspect one proc
168
+ bgo web
169
+
170
+ # Scripted: stop every online proc via JSON
171
+ bgo status --json | python3 -c '
172
+ import json, sys, subprocess
173
+ for p in json.load(sys.stdin):
174
+ if p["status"] == "online":
175
+ subprocess.run(["bgo", "stop", p["name"]])
176
+ '
177
+ ```
178
+
179
+ ## Status Table
180
+
181
+ The table auto-detects terminal capabilities and picks the best rendering:
182
+
183
+ | Level | Trigger | What you get |
184
+ |---|---|---|
185
+ | `plain` | non-TTY (pipes, CI logs), `TERM=dumb`, or `--plain` | ASCII only, no color, no glyphs |
186
+ | `normal` | TTY without UTF-8 locale | ANSI color + ASCII rules |
187
+ | `fancy` | TTY + UTF-8 locale (default) | ANSI color + Unicode box-drawing |
188
+
189
+ Override with `--plain` / `--fancy` or `BGO_TABLE=plain|normal|fancy`.
190
+
191
+ Sample (fancy):
192
+ ```
193
+ โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
194
+ โ”ƒ NAME STATUS PID CPU MEM UPTIME WATCH COMMAND โ”ƒ
195
+ โ”ฃโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ซ
196
+ โ”ƒ web โ— online 12345 2.5 0.1 00:05 โœ“ 0 python3 -m http.server 8080 โ”ƒ
197
+ โ”ƒ api โ— online 12346 0.0 0.0 01:23 โœ“ 3 node server.js โ”ƒ
198
+ โ”ƒ worker โ—‹ stopped - - - - โš  errored python3 worker.py โ”ƒ
199
+ โ”ƒ batch โ— online 12347 0.0 0.0 02:11 ยท ./batch โ”ƒ
200
+ โ”—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”›
201
+ Total: 4 | โ— online: 3 | โ—‹ stopped: 1
202
+
203
+ โš  1 errored:
204
+ worker โ€” 4 consecutive fast-crashes
205
+ bgo logs worker --watcher | bgo restart worker
206
+ ```
207
+
208
+ CPU / MEM / uptime are pulled in a single batched `ps` call regardless of how many procs are running.
209
+
210
+ ## Watch Mode
211
+
212
+ Watch mode runs a sidecar process per watched proc that polls the
213
+ target and restarts it on crash. State (restart count, error reason,
214
+ last stderr tail) is recorded in the proc JSON and surfaced via
215
+ `bgo status`.
216
+
217
+ ### Quick start
218
+
219
+ ```bash
220
+ bgo start -w myapi -- node server.js # start with watcher
221
+ bgo -w myapi node server.js # direct-mode variant
222
+ bgo watch myapi # attach to a running proc
223
+ bgo watch myapi --interval 5 --min-uptime 3 --on-fast-crash backoff
224
+ bgo unwatch myapi # detach, keep proc
225
+ bgo logs myapi --watcher # inspect events
226
+ ```
227
+
228
+ ### Fast-crash policy
229
+
230
+ If a process dies before `--min-uptime` (default 2s) it's a *fast crash*. Reaction depends on `--on-fast-crash`:
231
+
232
+ | Mode | Behavior |
233
+ |---|---|
234
+ | `backoff` (default) | Wait 2s, retry. Then 4s, then 8s. After 4 consecutive fast-crashes, mark `errored` and exit watcher. |
235
+ | `stop` | Mark `errored` on the first fast-crash. |
236
+ | `retry` | Retry indefinitely, capped at 8s backoff. |
237
+
238
+ When a proc enters `errored`:
239
+ - WATCH column shows `โš  errored` (or `[!] errored` in plain).
240
+ - Status footer summarizes errored procs and hints at the recovery commands.
241
+ - `bgo status <name>` detail shows the error reason and last stderr tail.
242
+ - `bgo restart <name>` clears the errored flag and re-spawns the watcher. Restart counter is **preserved** by default โ€” use `--reset-counters` to zero it.
243
+
244
+ ### Tunables
245
+
246
+ | Flag | Default | Notes |
247
+ |---|---|---|
248
+ | `--interval N` | 3 | Poll interval after the initial uptime window |
249
+ | `--min-uptime N` | 2 | Crash threshold; sub-window polled at high frequency |
250
+ | `--on-fast-crash MODE` | `backoff` | One of `backoff`, `stop`, `retry` |
251
+ | `--reset` | off | `bgo watch` only โ€” reset prior watch config to defaults |
252
+
253
+ ## Storage
254
+
255
+ - State: `~/.bgo/procs/<name>.json` โ€” one file per process, written atomically (tmp + `os.replace`)
256
+ - Logs: `~/.bgo/logs/<name>.out.log`, `<name>.err.log`, `<name>.watcher.log`
257
+
258
+ ## Testing
259
+
260
+ ```bash
261
+ python3 -m pytest tests/ -v
262
+ ```
263
+
264
+ 54 tests covering state I/O, atomic writes, command-shape detection, name derivation, liveness + zombie filtering, watch-config inheritance, and table rendering across all three levels.
265
+
266
+ ## Requirements
267
+
268
+ - Python 3.9+
269
+ - Linux or macOS (zombie detection is platform-aware: `/proc` on Linux, `ps -o stat=` on macOS)
270
+
271
+ ## License
272
+
273
+ MIT
@@ -0,0 +1,8 @@
1
+ bgo_cli/__init__.py,sha256=bZ2o5H2MXMEhmBwpsKjfp_aPEsRcqLLYAVv96N5qpfs,1660
2
+ bgo_cli/__main__.py,sha256=osHAkf0JqJYsKwJA0TDlaBtFfkTHgiDM6x_sdIcXWxY,131
3
+ bgo_cli/_core.py,sha256=M2rLIkz3HDzKKYw9aoH2N7h_ruzz0jv8tVlOLwxt2dY,69494
4
+ bgo_cli-0.2.0.dist-info/METADATA,sha256=wLLBt_qp35p5PiIGoSs-Fey4eUnw9ngOjmWqHe4JpjY,10668
5
+ bgo_cli-0.2.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
6
+ bgo_cli-0.2.0.dist-info/entry_points.txt,sha256=jwDszgvJCpsv05fSCItJzjtWObD5XQ5B8BBp_eZog34,37
7
+ bgo_cli-0.2.0.dist-info/licenses/LICENSE,sha256=TiPDFcGqqoLfVpAx-2uQLzOOkM-yhdpBIzjKKxf3hvg,1065
8
+ bgo_cli-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bgo = bgo_cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tcsenpai
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.