Unified server-side Python utility for the PocketShell Android client.
Project description
pocketshell
Unified server-side Python utility for the PocketShell Android client. The app probes for this single helper on each remote host and uses its subcommands for usage, tmux session/job metadata, agent conversations, QR host setup, repository discovery, environment files, hooks, logs, and daemon lifecycle checks.
Install
The recommended path is uv tool install, which lands the binary on PATH
under ~/.local/bin/:
uv tool install pocketshell
For local development from a clone:
cd tools/pocketshell
uv venv
uv pip install -e .
pocketshell --help
pipx install pocketshell works the same way for users who prefer
pipx. Both install paths produce a pocketshell binary that the
PocketShell app's bootstrap probe detects.
Optional extras
pocketshell qr-share requires the qrcode[pil] package (Pillow) to
render QR images. Because Pillow is heavy and not needed by any other
subcommand, it ships behind an optional qr extra:
uv tool install pocketshell --with qrcode[pil]
# or
pip install pocketshell[qr]
Without the extra, every other subcommand keeps working; only
pocketshell qr-share exits 127 with a friendly install hint.
Usage
Top-level commands in the current helper:
pocketshell usage [provider] [--json] # provider quota / usage
pocketshell sessions list [--by activity] # tmux session summaries
pocketshell jobs ... # tmux recurring jobs
pocketshell agent-log ... # agent conversation logs
pocketshell repos list ... # local / GitHub repositories
pocketshell env ... # .env / .envrc management
pocketshell hooks ... # Claude/Codex/OpenCode hooks
pocketshell logs ... # server-side trace sink
pocketshell daemon ... # IPC daemon lifecycle
pocketshell qr-share ... # SSH host QR import payloads
Run pocketshell --help or pocketshell <command> --help for the live
flag set. Some parity subcommands still proxy through the existing host
tools internally so their output remains byte-identical to what the app
already parses.
pocketshell usage
pocketshell usage # human-readable lines, one per provider
pocketshell usage --json # machine-readable JSON (consumed by the app)
pocketshell usage codex # filter to a single provider
The output shape is byte-identical to quse [provider] [--json]. When
the IPC daemon is running, usage --json dispatches usage.fetch over
the daemon socket and uses the daemon's short TTL cache; otherwise it
falls through to the one-shot subprocess path.
If quse is not installed, pocketshell usage exits with code 127 and
prints an install hint to stderr.
pocketshell repos list
Enumerate git repositories — either cloned on this host (--local) or
owned by the authenticated GitHub user (--remote). The two modes
share one unified JSON schema so a future merged view can interleave
them transparently.
pocketshell repos list --local # scan ~/git for clones (human)
pocketshell repos list --local --json # same, JSON output
pocketshell repos list --remote --json # via owner-only `gh api user/repos`
pocketshell repos list --remote --limit 20
Schema (every entry):
{
"owner": "alexeygrigorev", // null when remote URL is non-GitHub
"name": "pocketshell", // local dir basename, or GH repo name
"full_name": "alexeygrigorev/pocketshell", // null when owner unknown
"local": { // populated by --local scans
"path": "/home/alexey/git/pocketshell",
"head": "main"
},
"remote": { // populated by --remote scans
"default_branch": "main",
"html_url": "https://github.com/alexeygrigorev/pocketshell",
"ssh_url": "git@github.com:alexeygrigorev/pocketshell.git",
"updated_at": "2026-05-27T12:00:00Z"
}
}
--local scans ~/git by default (override with one or more --root
flags or the colon-separated POCKETSHELL_REPOS_ROOTS env var) and
populates local for every entry. owner and full_name are
best-effort from the parsed remote.origin.url; non-GitHub remotes
leave them null.
--remote delegates to gh api 'user/repos?affiliation=owner&sort=updated' --paginate --slurp.
Requires gh on PATH (apt install gh on Debian/Ubuntu,
brew install gh on macOS) authenticated via
gh auth login -s repo:read. Sorted by updated_at descending so the
picker shows the most-recently-touched repos first. Missing gh exits
127 with an install hint; a non-zero gh exit (auth missing,
rate-limit, etc.) propagates the exit code and stderr verbatim.
With neither flag, defaults to --local and prints a one-line
discoverability hint mentioning --remote.
Daemon mode caches repos.list_local for 10 s and repos.list_remote
for 5 min. --no-daemon forces the in-process path; --no-cache
forces the daemon to re-run upstream on the next call.
pocketshell qr-share
Builds a pocketshell.ssh-import.v1 payload from an ~/.ssh/config
alias (resolved via ssh -G) or from explicit flags, wraps it in one or
more pocketshell.qr.v1 chunked envelopes (matching the Kotlin
QrChunkCodec byte-for-byte), and emits QR codes for the phone-side
scanner to consume (issue #129).
pocketshell qr-share prod # ssh-config alias
pocketshell qr-share --host h --user u --key ~/.ssh/id_ed25519 --name h
pocketshell qr-share prod --png --out-dir /tmp/qr # write PNGs
pocketshell qr-share prod --print-only --id deadbeef # debug envelopes
When stdout is a TTY the QRs are drawn inline as Unicode blocks; between
multi-part transmissions the command pauses on "Press Enter for next
QR" so the user can scan each in turn. When stdout is not a TTY (or
--png is passed) a numbered PNG sequence (qr-share-01.png,
qr-share-02.png, ...) is written to --out-dir.
Requires the optional qr extra (see Optional extras).
Without it, the command exits 127 with the install hint and every other
subcommand keeps working.
Running from a repo clone (no install)
To run qr-share straight from a checkout without installing the tool,
use uv run from tools/pocketshell and include the qr extra:
cd tools/pocketshell
uv run --extra qr pocketshell qr-share prod
The first run creates .venv and installs the QR dependency; later runs
are instant. Run it in an interactive terminal so stdout is a TTY and the
QR renders inline — otherwise it falls back to writing PNGs (add
--png --out-dir ./qr to force PNGs). Omitting --extra qr makes the
command exit 127 with the install hint.
pocketshell hooks
Installs agent stop / idle-detection hooks across Claude Code,
Codex, and OpenCode and normalizes their events into a single
append-only JSONL bus the app can read back. Server-side only;
integration only — no "tell the agent to continue" action yet (deferred;
see issue #267 and locked decision D26 in docs/decisions.md).
pocketshell hooks install [--engine claude|codex|opencode|all] # default: all
pocketshell hooks status [--engine ...] [--json] [--last N]
pocketshell hooks events [--since ISO8601] [--limit N] [--json]
pocketshell hooks uninstall [--engine ...]
install is non-destructive — it merges, it never clobbers:
- Claude Code — adds a
{type: "command", command: "python3 <handler>"}entry under theStop,SubagentStop, andNotificationhook events in~/.claude/settings.json, only when absent. All other top-level keys and any pre-existing user hooks are preserved. - Codex — sets the top-level
notifyprogram in~/.codex/config.tomlto our handler (Codex hooks do not fire undercodex exec, sonotifyis the headless-safe signal). Ifnotifyis already set to something else, it warns and skips rather than overwriting. The rest of the TOML is preserved. - OpenCode — drops a
pocketshell-idle-signal.jsplugin into~/.config/opencode/plugin/without disturbing other plugins.
install is idempotent (running twice adds nothing new). Handler scripts
and the event bus live under ~/.cache/pocketshell/hooks/ (override with
$POCKETSHELL_HOOKS_DIR); each handler appends a normalized record
{ts, engine, state, source, session_id, cwd, ...} to
events.jsonl.
Per-engine uninstall (pocketshell hooks uninstall) removes only what
we added and is idempotent:
- Claude Code — drops our command group from each hook event; an
event key (and the top-level
hooksobject) is deleted only if we created it and it ends up empty. A user's pre-existing hooks always survive, so a pre-populatedsettings.jsoncomes back byte-equivalent for the unrelated parts. - Codex — removes the top-level
notifyline only when it still points at our handler. Anotifythe user pointed elsewhere is left alone. - OpenCode — deletes our plugin file; other plugins and the dir itself are left in place.
The event bus (events.jsonl) is preserved on uninstall so
already-emitted records stay readable; only the generated handler
scripts are cleaned up.
Development
cd tools/pocketshell
uv venv
uv pip install -e ".[dev]"
uv run pytest
Or via the dependency-group:
uv sync --group dev
uv run pytest
The tests stub quse.usage.collect_usage so they run in seconds without
hitting any provider API.
Release flow
pocketshell ships in lockstep with the Android app. Every time the
maintainer cuts an Android release tag (vX.Y.Z), the
Build workflow assembles the APK
and also builds the Python sdist + wheel and publishes them to PyPI.
Version coupling
Two files must agree on the release version:
app/build.gradle.kts->versionName = "X.Y.Z"tools/pocketshell/pyproject.toml->version = "X.Y.Z"
scripts/check-pypi-version.sh
enforces this. The release workflow runs it with --check-tag vX.Y.Z
before publishing, so a tag pushed with mismatched versions fails the
job loudly before anything reaches PyPI.
Run it locally before tagging:
scripts/check-pypi-version.sh # local match check
scripts/check-pypi-version.sh --check-tag vX.Y.Z
Bumping a release
- Pick the next semantic version after the latest GitHub Release/tag.
- Update both version sources in the same commit:
app/build.gradle.kts-> bumpversionName(andversionCode).tools/pocketshell/pyproject.toml-> bumpversionto the same value asversionName.
- Run
scripts/check-pypi-version.shto confirm they match. - Commit the bump on
main, push, and run the emulator release validation gate (scripts/release-emulator-validation.sh) as described inprocess.md-> "Release Builds". - Push the tag with
scripts/push-release-tag.sh. The tag-triggeredBuildworkflow then:- builds and uploads the APK + creates the GitHub Release
- runs
scripts/check-pypi-version.sh --check-tag vX.Y.Z - builds the Python sdist + wheel
- publishes them to PyPI via OIDC trusted publishing
The PyPI publish job depends on the APK build job, so a broken APK
build also aborts the PyPI publish. If only the PyPI publish fails the
maintainer can re-trigger the workflow at the same tag from the
Actions tab; the APK build is idempotent against an existing release
(softprops/action-gh-release updates the existing release rather
than failing).
PyPI trusted publishing setup (one-time)
The publish-pypi job uses GitHub's OIDC token instead of a long-lived
API token. This avoids storing a PYPI_API_TOKEN secret in the repo
and means there is nothing to rotate. The trade-off is that the
project owner must complete one configuration step on pypi.org before
the first automated tag publish:
- Sign in to https://pypi.org/ with the project owner account.
- Open the
pocketshellproject page -> Manage -> Publishing. - Under Trusted publishers, click Add a new pending publisher
(if the project is empty) or Add a new publisher, then fill in:
- PyPI Project Name:
pocketshell - Owner:
alexeygrigorev - Repository name:
pocketshell - Workflow name:
build.yml - Environment name:
pypi
- PyPI Project Name:
- Save the publisher.
- In this repository on GitHub, open
Settings -> Environments -> New environment -> name it
pypi. No secrets or reviewers are required; the environment exists purely to scope the OIDC token. (If the environment already exists, confirm it has no protection rules that would block the workflow from running.) - Push the next release tag. The
Publish to PyPI via trusted publishingstep should succeed without any token configuration.
Why trusted publishing (and not PYPI_API_TOKEN)?
- No long-lived secret to rotate, leak, or accidentally print in logs.
- The OIDC subject is scoped to
repo=alexeygrigorev/pocketshell,workflow=build.yml,environment=pypi, so a compromised fork or a different workflow file in this repo cannot reuse it. - D22 (no backwards-compat): we do not also maintain a token-fallback path. If trusted publishing breaks, fix it; do not add a token branch alongside.
If trusted publishing is ever unavailable for a tag (e.g. PyPI outage on the OIDC verifier), the recommended manual escape hatch is:
cd tools/pocketshell
python -m build
python -m twine upload dist/*
with the maintainer's account. Do not re-add a PYPI_API_TOKEN secret
as a permanent fallback.
Why a unified CLI?
The PocketShell app previously depended on multiple host-side tools.
That meant separate installs to keep up to date, separate probes to
surface failures from, and multiple PATH-discovery edge cases. A single
pocketshell binary collapses that app-facing contract into one install,
one probe, and one bootstrap row. The Android bootstrap probe now derives
PATH from the user's shell rc and prepends $HOME/.local/bin,
$HOME/bin, and $HOME/.cargo/bin before probing, so cloned-repo or
venv installs can be discovered without a manual app-side PATH field.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pocketshell-0.3.12.tar.gz.
File metadata
- Download URL: pocketshell-0.3.12.tar.gz
- Upload date:
- Size: 131.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28841b3d1464f6fa00cb5940d1543780cd2c907acfd133c69e664a44ed86c9ae
|
|
| MD5 |
f7a33d79fb9704ca4a64eb2fad774bf6
|
|
| BLAKE2b-256 |
817f165e62507e9ccb0ff0f3937644bd826b64e51dbbf7be88e450af1ce62c55
|
File details
Details for the file pocketshell-0.3.12-py3-none-any.whl.
File metadata
- Download URL: pocketshell-0.3.12-py3-none-any.whl
- Upload date:
- Size: 87.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2479eba867b9258c0fd453d90c3ac9bf0de8eaaaea97572021b755bfc1f6fcb5
|
|
| MD5 |
b69ef914ba56e184a54f5f4f27dbf79e
|
|
| BLAKE2b-256 |
47303af00c9a815f9232dfc7b44c6cc4c4fab3c1c168f199b398af554ecf0a1e
|