pocketshell 0.5.1__tar.gz → 0.5.3__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.
Files changed (104) hide show
  1. {pocketshell-0.5.1 → pocketshell-0.5.3}/PKG-INFO +2 -1
  2. pocketshell-0.5.3/pyproject.toml +265 -0
  3. pocketshell-0.5.3/src/pocketshell/aplexer.py +242 -0
  4. pocketshell-0.5.3/src/pocketshell/memcap.py +259 -0
  5. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/session_enum.py +224 -5
  6. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/sessions.py +735 -40
  7. pocketshell-0.5.3/tests/fixtures/aplexer/snapshot-agent.json +83 -0
  8. pocketshell-0.5.3/tests/fixtures/aplexer/snapshot-crashed-start.json +25 -0
  9. pocketshell-0.5.3/tests/fixtures/aplexer/snapshot-liveness-mix.json +113 -0
  10. pocketshell-0.5.3/tests/fixtures/aplexer/snapshot-mid-create.json +25 -0
  11. pocketshell-0.5.3/tests/fixtures/aplexer/snapshot-post-kill-window.json +79 -0
  12. pocketshell-0.5.3/tests/test_agents_fixture_aplexer.py +714 -0
  13. pocketshell-0.5.3/tests/test_aplexer_contract.py +813 -0
  14. pocketshell-0.5.3/tests/test_aplexer_resolution.py +518 -0
  15. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_profiles.py +52 -5
  16. pocketshell-0.5.3/tests/test_session_enum_schema2.py +1226 -0
  17. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_sessions_attach.py +178 -6
  18. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_sessions_create_routing.py +494 -3
  19. pocketshell-0.5.3/tests/test_sessions_kill.py +748 -0
  20. pocketshell-0.5.3/tests/test_sessions_mem_cap.py +953 -0
  21. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_watch_ci.py +13 -1
  22. {pocketshell-0.5.1 → pocketshell-0.5.3}/uv.lock +24 -1
  23. pocketshell-0.5.1/pyproject.toml +0 -148
  24. pocketshell-0.5.1/src/pocketshell/aplexer.py +0 -108
  25. pocketshell-0.5.1/tests/test_session_enum_schema2.py +0 -664
  26. {pocketshell-0.5.1 → pocketshell-0.5.3}/.gitignore +0 -0
  27. {pocketshell-0.5.1 → pocketshell-0.5.3}/README.md +0 -0
  28. {pocketshell-0.5.1 → pocketshell-0.5.3}/scheduler/README.md +0 -0
  29. {pocketshell-0.5.1 → pocketshell-0.5.3}/scheduler/pocketshell-usage-capture.service +0 -0
  30. {pocketshell-0.5.1 → pocketshell-0.5.3}/scheduler/pocketshell-usage-capture.timer +0 -0
  31. {pocketshell-0.5.1 → pocketshell-0.5.3}/scripts/sync-readme-exit-codes.py +0 -0
  32. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/__init__.py +0 -0
  33. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/__main__.py +0 -0
  34. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/agent_card_push.py +0 -0
  35. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/agent_log.py +0 -0
  36. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/agents.py +0 -0
  37. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/agents_kind.py +0 -0
  38. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/cards.py +0 -0
  39. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/cgroup_agents.py +0 -0
  40. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/cli.py +0 -0
  41. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/config.py +0 -0
  42. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/daemon.py +0 -0
  43. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/engines.py +0 -0
  44. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/env.py +0 -0
  45. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/github.py +0 -0
  46. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/hooks.py +0 -0
  47. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/jobs.py +0 -0
  48. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/logs.py +0 -0
  49. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/profiles.py +0 -0
  50. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/prune_attachments.py +0 -0
  51. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/push.py +0 -0
  52. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/qr_share.py +0 -0
  53. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/repos.py +0 -0
  54. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/resume.py +0 -0
  55. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/send.py +0 -0
  56. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/serve.py +0 -0
  57. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/tree.py +0 -0
  58. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/usage.py +0 -0
  59. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/usage_capture.py +0 -0
  60. {pocketshell-0.5.1 → pocketshell-0.5.3}/src/pocketshell/usage_reset.py +0 -0
  61. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/__init__.py +0 -0
  62. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/conftest.py +0 -0
  63. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.11-usage.json +0 -0
  64. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.13-usage.json +0 -0
  65. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.15-usage.json +0 -0
  66. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.15-usage.ndjson +0 -0
  67. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.15-usage.provenance.txt +0 -0
  68. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/quse-0.0.9-usage.json +0 -0
  69. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/data/sshd_anchor/Dockerfile.from-unanchored-base +0 -0
  70. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/fixtures/aplexer/snapshot-reported-state.json +0 -0
  71. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/fixtures/aplexer/snapshot.json +0 -0
  72. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agent_card_push.py +0 -0
  73. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agent_log.py +0 -0
  74. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agents.py +0 -0
  75. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agents_kind.py +0 -0
  76. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agents_kind_target.py +0 -0
  77. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_agents_source_target.py +0 -0
  78. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_cards.py +0 -0
  79. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_cards_push_notify.py +0 -0
  80. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_cgroup_agents.py +0 -0
  81. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_cli.py +0 -0
  82. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_daemon.py +0 -0
  83. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_daemon_fallback.py +0 -0
  84. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_engines.py +0 -0
  85. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_env.py +0 -0
  86. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_github.py +0 -0
  87. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_hooks.py +0 -0
  88. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_jobs.py +0 -0
  89. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_logs.py +0 -0
  90. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_prune_attachments.py +0 -0
  91. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_push.py +0 -0
  92. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_qr_share.py +0 -0
  93. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_repos.py +0 -0
  94. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_resume.py +0 -0
  95. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_send.py +0 -0
  96. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_serve.py +0 -0
  97. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_session_enum.py +0 -0
  98. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_sessions.py +0 -0
  99. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_ssh_fixture_penalties.py +0 -0
  100. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_tree.py +0 -0
  101. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_usage.py +0 -0
  102. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_usage_capture.py +0 -0
  103. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_usage_reset.py +0 -0
  104. {pocketshell-0.5.1 → pocketshell-0.5.3}/tests/test_watch_ci_cancelled.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pocketshell
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: Unified server-side Python utility for the PocketShell Android client.
5
5
  Project-URL: Homepage, https://github.com/alexeygrigorev/pocketshell
6
6
  Project-URL: Issues, https://github.com/alexeygrigorev/pocketshell/issues
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Topic :: Software Development
19
19
  Classifier: Topic :: System :: Monitoring
20
20
  Requires-Python: >=3.11
21
+ Requires-Dist: aplexer==0.1.4; sys_platform == 'linux'
21
22
  Requires-Dist: click>=8.2.0
22
23
  Requires-Dist: google-auth>=2.0.0
23
24
  Requires-Dist: pyyaml>=6.0
@@ -0,0 +1,265 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pocketshell"
7
+ # PLACEHOLDER (issue #2356, Phase 4 of epic #2350): this value is NEVER read
8
+ # for a real release. The publish-pypi job in .github/workflows/build.yml
9
+ # overwrites this field (in its ephemeral CI checkout only, never committed)
10
+ # from `scripts/derive-version.sh version-name --ref <tag>` — the SAME
11
+ # derivation app/build.gradle.kts uses for the Android versionName — right
12
+ # before building the sdist/wheel, so both sides derive from the git tag
13
+ # being released and can never independently drift.
14
+ # scripts/check-pypi-version.sh enforces the stamped value matches the tag;
15
+ # scripts/check-version-coupling.sh enforces the derivation itself is
16
+ # single-sourced. See tools/pocketshell/README.md ("Version coupling").
17
+ version = "0.5.3"
18
+ description = "Unified server-side Python utility for the PocketShell Android client."
19
+ readme = "README.md"
20
+ requires-python = ">=3.11"
21
+ authors = [{ name = "Alexey Grigorev" }]
22
+ license = { text = "MIT" }
23
+ keywords = ["pocketshell", "ssh", "tmux", "agents", "usage"]
24
+ classifiers = [
25
+ "Development Status :: 3 - Alpha",
26
+ "Environment :: Console",
27
+ "Intended Audience :: Developers",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
33
+ "Topic :: Software Development",
34
+ "Topic :: System :: Monitoring",
35
+ ]
36
+ # `pocketshell usage` delegates to the `quse` CLI, which is now a PINNED
37
+ # hard dependency (issue #1318): quse owns the unified usage schema, so we
38
+ # ship a known-good quse WITH pocketshell and invoke that pinned console-
39
+ # script (next to `sys.executable`, never PATH — see `pocketshell/usage.py`
40
+ # `_resolve_quse_binary`). A host-level quse upgrade must not reach us.
41
+ dependencies = [
42
+ "click>=8.2.0",
43
+ # Usage backend + single source of truth for the unified provider schema
44
+ # (issue #1318). Pinned exactly: `pocketshell usage --json` expects quse's
45
+ # provider-keyed `--json` document and fails loudly on schema drift, so the
46
+ # version is frozen, not a range. The published 0.0.15 wheel (upstream
47
+ # a86959e, issue #2293) is the six-provider CANONICAL producer: every
48
+ # record already carries the top-level `windows` map the Android parser
49
+ # reads, so the host boundary only injects the provider key and forwards
50
+ # the record unchanged. #2283's `short_term` / `long_term` translation for
51
+ # the older wheel is hard-cut (D22) — a legacy-shaped record now fails
52
+ # loudly. 0.0.15 is also the first published wheel that reports the `go`
53
+ # provider (OpenCode on the Go backend), so the OpenCode Go quota finally
54
+ # reaches the Usage panel; it is a provider of the pinned wheel, not a
55
+ # separate producer contract. 0.0.13 (#2195) historically added the `grok`
56
+ # provider; 0.0.11 (#1564) labeled each Codex window from its actual
57
+ # `limit_window_seconds`.
58
+ "quse==0.0.15",
59
+ # FCM HTTP v1 push delivery (#690): service-account OAuth2 bearer minting
60
+ # for `pocketshell push` / the `usage --capture` reset-push send. Imported
61
+ # lazily and fail-soft — a host without it (or without a Firebase
62
+ # credential) simply no-ops the send, so the lower bound is advisory.
63
+ "google-auth>=2.0.0",
64
+ # YAML serialization for `pocketshell profiles list` (#718) — the host's
65
+ # human/agent-readable default output format (#714). The Android client
66
+ # consumes the `--json` flag instead; the host-facing default is YAML.
67
+ "pyyaml>=6.0",
68
+ # Session create/resume delegates to the `tmuxctl` binary (see
69
+ # `pocketshell/resume.py`: `tmuxctl create-detached` / `create-or-attach`),
70
+ # so installing pocketshell pulls a tmuxctl that has the server-cgroup fix.
71
+ # >=0.3.3 is required: earlier tmuxctl started the shared tmux server inside
72
+ # the SSH login's `session-*.scope`, so a logout (or a per-session OOM) tore
73
+ # down every session at once; 0.3.3 starts the server in its own
74
+ # login-independent unit under robust.slice (tmuxctl#4). 0.3.0 first shipped
75
+ # the `create-detached` verb this CLI calls.
76
+ # >=0.3.5 is required as of 2026-08-26: 0.3.4 still resolves/creates
77
+ # sessions on the legacy shared socket only. A pinned-old pocketshell host
78
+ # CLI running alongside a newer interactive `tmuxctl`/`t` checkout (which
79
+ # does per-session servers) raced session creation for the same name onto
80
+ # two different sockets, so the app/desktop and an interactive `t` session
81
+ # silently disagreed about which sessions existed. 0.3.5 ships tmuxctl's
82
+ # per-session-server migration so every caller resolves sessions the same
83
+ # way.
84
+ "tmuxctl>=0.3.5",
85
+ # aplexer ships WITH the pocketshell CLI (issue #2543). `pocketshell
86
+ # sessions create --backend aplexer` needs BOTH the `a` CLI and its
87
+ # `aplexer` worker binary (aplexer/src/lib.rs::worker_executable resolves
88
+ # the worker as a sibling of current_exe); the published wheel bundles
89
+ # both native binaries and exposes them as the `a` / `aplexer`
90
+ # console-scripts, so `uv tool install pocketshell` delivers a complete,
91
+ # working aplexer with no separate build/copy/PATH step. That closes the
92
+ # reported failure where a hand-installed `~/bin/a` was invisible to the
93
+ # app's NON-INTERACTIVE SSH PATH and half-installed (no sibling worker).
94
+ #
95
+ # Pinned exactly, like `quse`: pocketshell speaks a specific `a --json`
96
+ # contract (`start`/`snapshot`/`list`/`launch-spec`/`engines`/`profiles`),
97
+ # and `pocketshell/aplexer.py` resolves the BUNDLED copy INSTEAD of PATH,
98
+ # so the pinned wheel is the ONLY aplexer this CLI can run. Bumping the
99
+ # pin is a deliberate, reviewed change.
100
+ #
101
+ # 0.1.4 is required for the session tree to say WHICH agent is running.
102
+ # Through 0.1.3 a snapshot row's only agent-ish field was `engine`, and
103
+ # `engine` cannot answer that question: every session PocketShell creates
104
+ # is `engine: "shell"` with the agent launched by hand inside it, so a
105
+ # tree full of claude/codex/opencode sessions is indistinguishable from a
106
+ # tree full of bare shells. 0.1.4 derives an `agent` field at QUERY time
107
+ # by walking the workload's descendant process tree (`workload_pid` plus
108
+ # `/proc/<pid>/task/*/children`, the same walk containment already uses)
109
+ # and classifying each `comm`/`cmdline` by whole-word command token —
110
+ # aplexer ca56fa5, spec.md section 18. It is present on every
111
+ # `a list --json` / `a snapshot` row (`null` when nothing recognisable is
112
+ # running) and never persisted, so it cannot go stale.
113
+ #
114
+ # `session_enum._aplexer_rows` reads that key straight onto
115
+ # `LiveSession.agent` and schema 2 emits it on every row. Against 0.1.3
116
+ # the key is simply absent and every row reports `agent: null` — the
117
+ # listing still works, it just cannot name an agent, which is the whole
118
+ # point of the bump. tests/test_aplexer_contract.py pins the behaviour
119
+ # against the bundled binary: a real session running a process named
120
+ # `claude` reports `agent == "claude"`, and `null` again once it exits.
121
+ # Verified red on published 0.1.3 (no `agent` key at all), green on 0.1.4.
122
+ #
123
+ # 0.1.3 is required for a USER-VISIBLE session-tree defect, not for
124
+ # version hygiene (aplexer#2 / aplexer#3). Through 0.1.2, aplexer's
125
+ # `list_records` treated a session directory containing no `session.json`
126
+ # as a CORRUPT REGISTRY and failed the entire scan:
127
+ #
128
+ # a: load session registry entry <dir>: read <dir>/session.json:
129
+ # No such file or directory (os error 2) exit=1
130
+ #
131
+ # But `start_session` creates that directory 26-43 ms BEFORE it writes the
132
+ # record, on every single `a start`. The window is therefore on the normal
133
+ # create path, and every reader that does not hold the registry lock can
134
+ # land in it — which is every reader PocketShell has. `a watch` died on it
135
+ # (1 run in 60 on an idle box) and `a list` was bricked outright for the
136
+ # duration.
137
+ #
138
+ # That reaches the phone directly. `session_enum.py::_probe_aplexer` and
139
+ # `sessions.py::_aplexer_snapshot` both probe `a --json snapshot` and fall
140
+ # back to `a --json list`; the fallback cannot help, because the failure
141
+ # is in the shared registry scan underneath both. `aplexer.run_json`
142
+ # collapses any failure to None, so while a session was being created the
143
+ # session tree silently lost EVERY aplexer row. Worse, a record-less
144
+ # directory that outlives the window (a killed/crashed `a start`) bricks
145
+ # 0.1.2's registry permanently — including `a start` itself, which runs
146
+ # the same scan under the lock, so `sessions create --backend aplexer`
147
+ # stops working until someone manually `rmdir`s it.
148
+ # tests/test_aplexer_contract.py drives the bundled binary through both
149
+ # production probes with exactly that on-disk shape; verified red on
150
+ # published 0.1.2, green on 0.1.3.
151
+ #
152
+ # 0.1.2 (not 0.1.1) was the previous floor, and the version string alone
153
+ # could not tell you why: aplexer HEAD sat 143 commits past the v0.1.1 tag
154
+ # while STILL self-reporting `a --version` as 0.1.1, so the published
155
+ # 0.1.1 wheel and the build every PocketShell host actually ran were
156
+ # indistinguishable by version. Pinning 0.1.1 under the hard cut would
157
+ # have silently DOWNGRADED every host to a build missing two fixes the
158
+ # real create-agent path needs:
159
+ # * aplexer ee4b957 — profile `executable` override (argv[0]) for Codex
160
+ # variants. Without it, `[profiles.zcodex] engine="codex",
161
+ # executable="zcodex"` resolves argv[0] to `codex`, and `pocketshell
162
+ # sessions create --backend aplexer --engine codex --profile zcodex`
163
+ # dies with "a: command is not executable or was not found in PATH:
164
+ # codex".
165
+ # * aplexer d13ecb2 — preserve the provider environment for plain
166
+ # `shell` launches (0.1.1 stripped 71 provider vars from every shell
167
+ # session).
168
+ # tests/test_aplexer_contract.py pins ALL of these behaviours against the
169
+ # BUNDLED binary, because `a --version` demonstrably cannot: a future pin
170
+ # that regresses to a build without them fails that test loudly instead
171
+ # of shipping a silent downgrade. Re-run it whenever this pin moves.
172
+ #
173
+ # There is no separate release-time guard for the aplexer version itself
174
+ # (scripts/check-pypi-version.sh only couples pocketshell's OWN version to
175
+ # the release tag and says nothing about quse or tmuxctl either), so the
176
+ # exact pin + the committed uv.lock + that contract test are the
177
+ # enforcement.
178
+ #
179
+ # The `sys_platform == 'linux'` marker is load-bearing: aplexer publishes
180
+ # manylinux wheels only (x86_64 + aarch64) and NO sdist, so an unmarked
181
+ # hard dependency would make `pip install pocketshell` unresolvable on
182
+ # macOS/Windows. PocketShell hosts are Linux; a non-Linux host simply gets
183
+ # no bundled aplexer at all, so `sessions create --backend aplexer` there
184
+ # fails loud (there is no PATH fallback — D22) while tmux, the default
185
+ # backend, keeps working.
186
+ #
187
+ # Install-surface note (unchanged in 0.1.4): as of 0.1.2 the wheels moved
188
+ # from manylinux_2_17 to manylinux_2_28, raising the minimum glibc from
189
+ # 2.17 to 2.28. Linux hosts older than that (CentOS 7, Ubuntu 18.04) can
190
+ # no longer install pocketshell at all now that aplexer is a hard
191
+ # dependency. Flagged, not solved here — see docs/aplexer-integration.md.
192
+ "aplexer==0.1.4; sys_platform == 'linux'",
193
+ ]
194
+
195
+ [project.scripts]
196
+ pocketshell = "pocketshell.cli:main"
197
+
198
+ [project.urls]
199
+ Homepage = "https://github.com/alexeygrigorev/pocketshell"
200
+ Issues = "https://github.com/alexeygrigorev/pocketshell/issues"
201
+
202
+ [dependency-groups]
203
+ dev = [
204
+ "pytest>=8.4.0",
205
+ "ruff>=0.15.0",
206
+ ]
207
+
208
+ [project.optional-dependencies]
209
+ # Mirror of the dev `dependency-groups` so `pip install -e ".[dev]"` and
210
+ # `uv pip install -e ".[dev]"` both work for CI and ad-hoc local setups.
211
+ # `uv sync --group dev` reads `dependency-groups`; PEP-621 tooling reads
212
+ # `optional-dependencies`. Keeping both in lock-step is cheap.
213
+ dev = [
214
+ "pytest>=8.4.0",
215
+ "ruff>=0.15.0",
216
+ ]
217
+ # Optional extra for `pocketshell qr-share`. The `qrcode[pil]` chain is
218
+ # heavy (Pillow) and is only needed for QR rendering, so we keep it out
219
+ # of the default install. Without this extra, `pocketshell qr-share`
220
+ # exits 127 with a friendly install hint; every other subcommand keeps
221
+ # working unchanged. Install with `pip install pocketshell[qr]` or
222
+ # `uv tool install pocketshell --with qrcode[pil]`.
223
+ qr = [
224
+ "qrcode[pil]>=7.4",
225
+ ]
226
+
227
+ [tool.hatch.build.targets.wheel]
228
+ packages = ["src/pocketshell"]
229
+
230
+ [tool.hatch.build.targets.sdist]
231
+ exclude = [
232
+ "/.github",
233
+ "/.pytest_cache",
234
+ "/.ruff_cache",
235
+ "/.venv",
236
+ "/dist",
237
+ ]
238
+
239
+ [tool.uv]
240
+ # CI and local frozen-sync checks use the same installer semantics. Bump this
241
+ # deliberately together with .github/workflows/tests.yml and validate the
242
+ # committed lock before merging.
243
+ required-version = "==0.10.11"
244
+ # Keep the lockfile's reproducibility cutoff project-local. The host may have
245
+ # a rolling global `exclude-newer` policy that predates deliberately pinned
246
+ # releases (quse 0.0.15 and tmuxctl 0.3.5); this exact value is also the
247
+ # `uv.lock` options cutoff and must be used when checking this lock. Moved
248
+ # past quse 0.0.15's 2026-08-28T12:09:07Z PyPI upload for issue #2293, then
249
+ # past aplexer 0.1.2's 2026-09-05T22:38:08Z PyPI upload (its `aplexer-client`
250
+ # runtime dep landed at 22:38:04Z) for issue #2543. A package uploaded after
251
+ # the cutoff is simply invisible to `uv lock`, which reads like a broken index
252
+ # rather than a stale cutoff, so this value moves in lock-step with every new
253
+ # pin — and the `uv.lock` options cutoff must be moved to match. Now past
254
+ # aplexer 0.1.3's 2026-09-06T00:32:09Z PyPI upload (its `aplexer-client`
255
+ # runtime dep landed at 00:32:04Z) for the session-tree regression fix above,
256
+ # and now past aplexer 0.1.4's 2026-09-06T16:14:52Z PyPI upload (its
257
+ # `aplexer-client` runtime dep landed at 16:14:48Z) for the `agent` field.
258
+ exclude-newer = "2026-09-06T17:00:00Z"
259
+
260
+ [tool.pytest.ini_options]
261
+ testpaths = ["tests"]
262
+
263
+ [tool.ruff]
264
+ line-length = 100
265
+ target-version = "py311"
@@ -0,0 +1,242 @@
1
+ """Host-local client for the ``a`` binary (aplexer Phase A).
2
+
3
+ PocketShell and aplexer share a machine: the helper invokes ``a --json …``
4
+ and overlays presentation/tmux concerns. Probe failures are silent and
5
+ return ``None`` so every call site can fall back to the native path.
6
+
7
+ Kill switches (any one is enough to skip):
8
+
9
+ - ``POCKETSHELL_APLEXER=0`` — master
10
+ - ``POCKETSHELL_APLEXER_PROFILES=0``
11
+ - ``POCKETSHELL_APLEXER_ENGINES=0``
12
+ - ``POCKETSHELL_APLEXER_LAUNCH=0``
13
+ - ``POCKETSHELL_APLEXER_SESSIONS=0``
14
+
15
+ Binary resolution (issue #2543)
16
+ -------------------------------
17
+
18
+ aplexer ships WITH this CLI: PyPI ``aplexer`` is a pinned, Linux-marked hard
19
+ dependency (``pyproject.toml``), so ``uv tool install pocketshell`` drops the
20
+ ``a`` and ``aplexer`` console-scripts into the SAME ``bin`` directory as the
21
+ interpreter running pocketshell. There is no separate aplexer install step and
22
+ no PATH surgery. Resolution order, highest first:
23
+
24
+ 1. ``APLEXER_BIN`` — the one explicit override (a debug/test knob, not an
25
+ install path).
26
+ 2. The **bundled** copy next to ``sys.executable`` — the pinned wheel, the
27
+ same anchor ``usage.py::_resolve_quse_binary`` uses for the pinned ``quse``.
28
+
29
+ There is no third step: the ``PATH`` lookup is HARD-CUT (D22 — no fallback
30
+ branch; the superseded code is deleted, not conditioned). This mirrors
31
+ ``quse`` exactly. A host-level or locally-built ``a`` on ``PATH`` must NOT
32
+ shadow the pinned copy, and an absent bundled copy is a packaging-integrity
33
+ error that fails loud — not a "please install aplexer" nag. aplexer is a
34
+ dependency of this CLI; it is never installed separately.
35
+
36
+ The original bug this fixes: ``which_a`` used to be a bare
37
+ ``shutil.which("a", path=env["PATH"])``, and the app drives the host CLI over
38
+ a NON-INTERACTIVE SSH command whose PATH is
39
+ ``~/.local/bin:/usr/local/sbin:…`` — a correctly installed ``a`` outside those
40
+ dirs (e.g. ``~/bin/a``) was invisible, and the error said "not installed".
41
+
42
+ ``a`` needs a sibling ``aplexer`` worker binary (``aplexer/src/lib.rs``
43
+ ``worker_executable`` resolves it next to ``current_exe``, else bare
44
+ ``aplexer`` on PATH). The pinned wheel always ships both into the same dir, so
45
+ :class:`AplexerResolution` reports the worker it found next to ``a``.
46
+
47
+ A BUNDLED ``a`` with no sibling worker is therefore a packaging-integrity
48
+ failure, not a usable resolution (issue #2553): accepting it would let the
49
+ pinned CLI start an UNPINNED worker off ``PATH`` — the same separate-install
50
+ hazard #2543 removed, one level down. Such a candidate is skipped with a
51
+ ``tried`` entry saying why, so the caller's existing "could not resolve `a`;
52
+ tried …" message explains it instead of a low-level worker-startup error.
53
+ ``APLEXER_BIN`` is deliberately exempt: it is the one explicit override ("run
54
+ exactly this binary"), the reinstall advice does not apply to it, and it is
55
+ the seam the test suite's stub ``a`` uses.
56
+ """
57
+
58
+ from __future__ import annotations
59
+
60
+ import json
61
+ import os
62
+ import signal
63
+ import subprocess
64
+ import sys
65
+ from dataclasses import dataclass, field
66
+ from pathlib import Path
67
+ from typing import Any, Mapping, Optional
68
+
69
+ JSON_TIMEOUT_S = 2.0
70
+ LAUNCH_TIMEOUT_S = 5.0
71
+ BIN_ENV = "APLEXER_BIN"
72
+ # Snapshot Popen so helper tests that patch ``subprocess.Popen`` (to block
73
+ # the source-recorder child) cannot swallow ``a`` probes.
74
+ _Popen = subprocess.Popen
75
+ _TimeoutExpired = subprocess.TimeoutExpired
76
+ MASTER_KILL = "POCKETSHELL_APLEXER"
77
+ FEATURE_KILLS = {
78
+ "profiles": "POCKETSHELL_APLEXER_PROFILES",
79
+ "engines": "POCKETSHELL_APLEXER_ENGINES",
80
+ "launch": "POCKETSHELL_APLEXER_LAUNCH",
81
+ "sessions": "POCKETSHELL_APLEXER_SESSIONS",
82
+ }
83
+
84
+
85
+ def env_map(env: Optional[Mapping[str, str]] = None) -> dict[str, str]:
86
+ merged = dict(os.environ)
87
+ if env:
88
+ merged.update({str(k): str(v) for k, v in env.items()})
89
+ return merged
90
+
91
+
92
+ def enabled(feature: str, env: Optional[Mapping[str, str]] = None) -> bool:
93
+ source = env_map(env)
94
+ if source.get(MASTER_KILL) == "0":
95
+ return False
96
+ kill = FEATURE_KILLS.get(feature)
97
+ if kill and source.get(kill) == "0":
98
+ return False
99
+ return True
100
+
101
+
102
+ @dataclass(frozen=True)
103
+ class AplexerResolution:
104
+ """Outcome of resolving the ``a`` CLI, including what was tried.
105
+
106
+ ``tried`` is human-readable and exists so a failure can NAME the candidate
107
+ paths instead of claiming aplexer "is not installed" (issue #2543).
108
+ """
109
+
110
+ path: Optional[str] = None
111
+ source: Optional[str] = None
112
+ worker: Optional[str] = None
113
+ tried: tuple[str, ...] = field(default_factory=tuple)
114
+
115
+
116
+ def _bundled_bin_dirs() -> list[Path]:
117
+ """Directories that can hold the pinned aplexer console-scripts.
118
+
119
+ Console-scripts live next to the UNRESOLVED ``sys.executable``: in a venv
120
+ (or a ``uv tool`` install) ``bin/python`` is a symlink to the underlying
121
+ interpreter, so ``Path(sys.executable).resolve()`` points at the shared
122
+ interpreter dir where ``a`` is NOT installed. Check the interpreter's own
123
+ ``bin`` dir first and only fall through to the resolved dir for layouts
124
+ where the two coincide. Both candidates are anchored to ``sys.executable``
125
+ — this is NOT a PATH search. Same trap, same handling, as
126
+ ``usage.py::_resolve_quse_binary``.
127
+ """
128
+ exe_dir = Path(sys.executable).parent
129
+ dirs = [exe_dir]
130
+ resolved_dir = Path(sys.executable).resolve().parent
131
+ if resolved_dir != exe_dir:
132
+ dirs.append(resolved_dir)
133
+ return dirs
134
+
135
+
136
+ def _sibling_worker(cli_path: str) -> Optional[str]:
137
+ """The ``aplexer`` worker binary shipped next to ``cli_path``, if any."""
138
+ worker = Path(cli_path).parent / "aplexer"
139
+ return str(worker) if worker.exists() else None
140
+
141
+
142
+ def resolve_a(env: Optional[Mapping[str, str]] = None) -> AplexerResolution:
143
+ """Resolve the ``a`` CLI: ``APLEXER_BIN``, else the BUNDLED copy. No PATH.
144
+
145
+ See the module docstring: ``PATH`` is deliberately not consulted at all,
146
+ so a separately-installed ``a`` can never be load-bearing. Never raises —
147
+ an unresolvable ``a`` comes back as a report whose ``path`` is ``None``
148
+ and whose ``tried`` lists every candidate, for the caller's error message.
149
+ A bundled ``a`` missing its sibling ``aplexer`` worker counts as
150
+ unresolvable (#2553), for the reason the module docstring gives.
151
+ """
152
+ source = env_map(env)
153
+ tried: list[str] = []
154
+
155
+ explicit = source.get(BIN_ENV)
156
+ if explicit:
157
+ return AplexerResolution(
158
+ path=explicit,
159
+ source=BIN_ENV,
160
+ worker=_sibling_worker(explicit),
161
+ tried=(f"{BIN_ENV}={explicit}",),
162
+ )
163
+ tried.append(f"{BIN_ENV} (unset)")
164
+
165
+ for bin_dir in _bundled_bin_dirs():
166
+ candidate = bin_dir / "a"
167
+ if candidate.exists():
168
+ worker = _sibling_worker(str(candidate))
169
+ if worker is None:
170
+ # HALF-INSTALLED BUNDLE (#2553). `a` alone is not usable:
171
+ # `aplexer/src/lib.rs::worker_executable` resolves the worker
172
+ # next to `current_exe` and, failing that, runs a BARE
173
+ # `aplexer` off PATH — so returning this `a` would either
174
+ # start an unpinned worker (the separate-install hazard #2543
175
+ # removed, one level down) or die with a low-level startup
176
+ # error. Treated exactly like an absent `a`: keep looking, and
177
+ # if nothing answers, fail loud with this candidate named.
178
+ tried.append(
179
+ f"{candidate} (bundled, found; sibling `aplexer` worker "
180
+ "missing — half-installed)"
181
+ )
182
+ continue
183
+ return AplexerResolution(
184
+ path=str(candidate),
185
+ source="bundled",
186
+ worker=worker,
187
+ tried=tuple([*tried, f"{candidate} (bundled, found)"]),
188
+ )
189
+ tried.append(f"{candidate} (bundled, missing)")
190
+
191
+ # No PATH lookup by design (D22 hard cut, issue #2543): resolution ends
192
+ # here. An `a` that exists only on PATH is a SEPARATE install, which is the
193
+ # mode this change removes — it must not be picked up silently.
194
+ return AplexerResolution(tried=tuple(tried))
195
+
196
+
197
+ def which_a(env: Optional[Mapping[str, str]] = None) -> Optional[str]:
198
+ """Path to the ``a`` CLI, or ``None``. Thin wrapper over :func:`resolve_a`."""
199
+ return resolve_a(env).path
200
+
201
+
202
+ def run_json(
203
+ args: list[str],
204
+ *,
205
+ env: Optional[Mapping[str, str]] = None,
206
+ timeout: Optional[float] = None,
207
+ feature: Optional[str] = None,
208
+ ) -> Any | None:
209
+ """Run ``a --json <args>`` and parse stdout. None on skip or any failure."""
210
+ if timeout is None:
211
+ timeout = JSON_TIMEOUT_S
212
+ if feature and not enabled(feature, env):
213
+ return None
214
+ cli = which_a(env)
215
+ if cli is None:
216
+ return None
217
+ try:
218
+ proc = _Popen(
219
+ [cli, "--json", *args],
220
+ stdout=subprocess.PIPE,
221
+ stderr=subprocess.PIPE,
222
+ text=True,
223
+ env=env_map(env),
224
+ start_new_session=True,
225
+ )
226
+ try:
227
+ stdout, _stderr = proc.communicate(timeout=timeout)
228
+ except _TimeoutExpired:
229
+ try:
230
+ os.killpg(proc.pid, signal.SIGKILL)
231
+ except OSError:
232
+ proc.kill()
233
+ proc.communicate()
234
+ return None
235
+ except OSError:
236
+ return None
237
+ if proc.returncode != 0:
238
+ return None
239
+ try:
240
+ return json.loads(stdout)
241
+ except json.JSONDecodeError:
242
+ return None