workspaceguard-cli 0.1.1__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,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: workspaceguard-cli
3
+ Version: 0.1.1
4
+ Summary: Per-workspace usage metering and quota caps for shared self-hosted AI assistant deployments (Odysseus and compatible backends).
5
+ Project-URL: Homepage, https://github.com/RudrenduPaul/workspaceguard
6
+ Project-URL: Repository, https://github.com/RudrenduPaul/workspaceguard
7
+ Project-URL: Bug Tracker, https://github.com/RudrenduPaul/workspaceguard/issues
8
+ Project-URL: Changelog, https://github.com/RudrenduPaul/workspaceguard/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/RudrenduPaul/workspaceguard/blob/main/docs/getting-started.md
10
+ Project-URL: Author - Rudrendu Paul, https://github.com/RudrenduPaul
11
+ Project-URL: Author - Sourav Nandy, https://github.com/Sourav-nandy-ai
12
+ Author: Rudrendu Paul, Sourav Nandy
13
+ License-Expression: MIT
14
+ License-File: LICENSE
15
+ Keywords: agent-native,ai-assistant,billing,cli,multi-tenant,odysseus,quota,reverse-proxy,self-hosted,usage-metering
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Environment :: Console
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Topic :: Security
28
+ Classifier: Topic :: System :: Systems Administration
29
+ Requires-Python: >=3.9
30
+ Requires-Dist: cryptography<46,>=42
31
+ Requires-Dist: pyyaml<7,>=6.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: build<2,>=1.0; extra == 'dev'
34
+ Requires-Dist: pytest-asyncio<1,>=0.23; extra == 'dev'
35
+ Requires-Dist: pytest<9,>=7.0; extra == 'dev'
36
+ Requires-Dist: twine<7,>=5.0; extra == 'dev'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # workspaceguard-cli (Python)
40
+
41
+ Per-workspace usage metering and quota caps for one shared self-hosted AI
42
+ assistant deployment -- a genuine, independent Python port of the
43
+ [`workspaceguard-cli`](https://github.com/RudrenduPaul/workspaceguard) npm
44
+ package, not a wrapper around a Node binary.
45
+
46
+ [![PyPI version](https://img.shields.io/pypi/v/workspaceguard-cli.svg)](https://pypi.org/project/workspaceguard-cli/)
47
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/RudrenduPaul/workspaceguard/blob/main/LICENSE)
48
+ [![Python versions](https://img.shields.io/pypi/pyversions/workspaceguard-cli.svg)](https://pypi.org/project/workspaceguard-cli/)
49
+
50
+ ## Why this exists
51
+
52
+ Run [Odysseus](https://github.com/pewdiepie-archdaemon/odysseus) (or a
53
+ compatible self-hosted assistant) for your whole household or small team,
54
+ and there is no way to see who sent how many messages this month, or to
55
+ stop one person's usage from burning through everyone else's API budget.
56
+ WorkspaceGuard is a thin sidecar that adds that layer: per-workspace
57
+ message counts, optional monthly caps that fail closed, and a CLI report
58
+ an admin (or another agent) can read.
59
+
60
+ This project originally set out to add per-user workspace isolation
61
+ (separate chat history, memory, API keys) to a self-hosted AI chat
62
+ platform. A feasibility spike found that premise was false for the target
63
+ platform's current default configuration: per-user ownership on chat
64
+ history, memory, and API tokens is already enforced by default. Rather
65
+ than ship a competing reimplementation of something the target platform
66
+ already does correctly, this project keeps its tested isolation engine
67
+ (namespace separation, an AES-256-GCM vault with real key rotation,
68
+ fail-closed identity resolution, a self-healing circuit breaker) as the
69
+ identity-resolution substrate, and builds the layer that platform
70
+ genuinely does not have: usage metering and quota enforcement per
71
+ workspace. See the [project README](https://github.com/RudrenduPaul/workspaceguard#readme)
72
+ for the full story.
73
+
74
+ ## Install
75
+
76
+ ```bash
77
+ pip install workspaceguard-cli
78
+ ```
79
+
80
+ **Current status**: this Python port is fully built, tested (32/32 pytest
81
+ tests passing), and packaged -- the wheel and sdist are built and verified,
82
+ installing and running correctly end to end in a fresh virtual environment.
83
+ The first PyPI publish is pending: PyPI's own account-level throttle on
84
+ registering brand-new project names ("429 Too many new projects created")
85
+ is currently blocking the upload, unrelated to any 2FA requirement (this
86
+ account's PyPI publishing needs no human 2FA). It will publish as soon as
87
+ that throttle window clears. Separately, the npm package (`workspaceguard-cli`)
88
+ is built with CI green but not yet published to the npm registry either
89
+ (blocked on a manual 2FA-gated publish step). Neither `pip install
90
+ workspaceguard-cli` nor `npm install -g workspaceguard-cli` is live yet as
91
+ of this writing -- check [PyPI](https://pypi.org/project/workspaceguard-cli/)
92
+ for current availability. This package is a genuine, independent port --
93
+ not a wrapper around the npm package -- so it will work regardless of npm's
94
+ status once it publishes.
95
+
96
+ ## Quickstart
97
+
98
+ ```bash
99
+ # Register the workspaces sharing one deployment (identity = the header
100
+ # value your reverse proxy sets after authenticating, e.g. Cloudflare
101
+ # Access).
102
+ workspaceguard add-workspace alex --identity alex@example.com
103
+ workspaceguard add-workspace jordan --identity jordan@example.com
104
+
105
+ # Optional: cap alex at 1000 messages/month. Omit for unlimited (the default).
106
+ workspaceguard set-cap alex 1000
107
+
108
+ # See usage for every workspace.
109
+ workspaceguard usage
110
+ ```
111
+
112
+ ```
113
+ $ workspaceguard usage --json
114
+ {"ok": true, "usage": [{"workspaceId": "alex", "identity": "alex@example.com", "monthlyMessageCap": 1000, "percentUsed": 0, "period": "2026-07", "messageCount": 0, "estimatedBytes": 0}]}
115
+ ```
116
+
117
+ ## CLI reference
118
+
119
+ Every command accepts `--json` for a structured, agent-native output shape
120
+ instead of the human-readable text shown below. Identical command surface
121
+ to the npm CLI.
122
+
123
+ | Command | What it does |
124
+ | --- | --- |
125
+ | `workspaceguard init` | Initializes the data directory and vault for this deployment. |
126
+ | `workspaceguard add-workspace <id> --identity <value>` | Registers a workspace, idempotent on repeat calls for the same id. |
127
+ | `workspaceguard status [--json]` | Lists configured workspaces. |
128
+ | `workspaceguard usage [--json]` | Per-workspace message count, cap, and percent-used for the current month. |
129
+ | `workspaceguard set-cap <id> <count\|none>` | Sets or clears a workspace's monthly message cap. |
130
+ | `workspaceguard rotate-key <id>` | Rotates a workspace's vault encryption key (invalidates the old ciphertext). |
131
+ | `workspaceguard scan [--json]` | Isolation config scan (scaffold stub, carried over from the original build). |
132
+
133
+ ## Library API
134
+
135
+ ```python
136
+ import asyncio
137
+ from workspaceguard import create_workspace_guard, MockAdapter, QuotaExceededError
138
+
139
+ async def main():
140
+ guard = await create_workspace_guard(data_dir="./data", backend=MockAdapter())
141
+ await guard.add_workspace("alex", "alex@example.com")
142
+ await guard.set_cap("alex", 1000)
143
+
144
+ try:
145
+ await guard.chat("alex@example.com", "hello")
146
+ except QuotaExceededError:
147
+ pass # alex is over their monthly cap
148
+
149
+ report = await guard.usage_report()
150
+
151
+ asyncio.run(main())
152
+ ```
153
+
154
+ The library API is async (`asyncio`), matching the async architecture of
155
+ the original TypeScript source rather than flattening it to synchronous
156
+ calls.
157
+
158
+ ## How it works
159
+
160
+ ```
161
+ target: an inbound chat request with an identity header value
162
+ -> resolve_workspace() -- fail closed on any miss, never a default workspace
163
+ -> check_quota() -- QuotaExceededError if the workspace is at its cap
164
+ -> circuit breaker -- calls the BackendAdapter, opens after 3 consecutive
165
+ failures, self-heals via a half-open probe after a cooldown
166
+ -> record usage -- per-workspace, per-month counters with automatic
167
+ period rollover
168
+ ```
169
+
170
+ - `workspaceguard/isolation_guard.py` -- the single choke point (`chat()`)
171
+ every request flows through: resolve workspace -> check quota -> call
172
+ backend -> record usage.
173
+ - `workspaceguard/usage.py` -- the usage-metering engine this project adds:
174
+ per-workspace, per-month counters with automatic period rollover, and
175
+ `QuotaExceededError` enforcement.
176
+ - `workspaceguard/vault.py`, `workspaceguard/namespace.py`,
177
+ `workspaceguard/circuit_breaker.py` -- the original isolation-engine
178
+ code, kept as the identity/workspace-boundary substrate the metering
179
+ layer reads from, not shipped as a competing isolation product.
180
+ - `workspaceguard/adapters/` -- `BackendAdapter` abstract base class; a
181
+ real Odysseus HTTP adapter is the next step (currently `MockAdapter`
182
+ only, same as the TypeScript original).
183
+
184
+ Backend-specific behavior never enters the core modules directly --
185
+ everything goes through `BackendAdapter`.
186
+
187
+ ## Trust boundary
188
+
189
+ WorkspaceGuard trusts an upstream identity header (default:
190
+ `Cf-Access-Authenticated-User-Email`) to resolve the workspace. It must
191
+ never be directly reachable from the network -- only from behind whatever
192
+ trusted proxy sets that header (Cloudflare Access, Tailscale, etc.). This
193
+ is documented, not code-enforced.
194
+
195
+ ## What's real vs. not yet built
196
+
197
+ - Real, tested (28/28 pytest tests passing): usage metering, quota
198
+ enforcement, the original isolation engine (vault, namespace separation,
199
+ circuit breaker), CLI with `--json` mode.
200
+ - Not yet built: a real Odysseus HTTP adapter (only `MockAdapter` exists so
201
+ far, same as the TypeScript original), a hosted managed billing
202
+ dashboard (deliberately out of scope for this MIT project).
203
+
204
+ ## Security
205
+
206
+ The vault uses AES-256-GCM (via the `cryptography` package) with one
207
+ derived key per workspace per generation -- rotating a workspace's key
208
+ increments its generation, so old ciphertext genuinely can no longer be
209
+ decrypted, not a no-op. See
210
+ [SECURITY.md](https://github.com/RudrenduPaul/workspaceguard/blob/main/SECURITY.md)
211
+ for the disclosure process and what's in/out of scope.
212
+
213
+ ## Contributing
214
+
215
+ See [CONTRIBUTING.md](https://github.com/RudrenduPaul/workspaceguard/blob/main/CONTRIBUTING.md).
216
+
217
+ ```bash
218
+ cd python
219
+ python3 -m venv .venv && source .venv/bin/activate
220
+ pip install -e ".[dev]"
221
+ pytest
222
+ ```
223
+
224
+ ## License
225
+
226
+ MIT, see [LICENSE](https://github.com/RudrenduPaul/workspaceguard/blob/main/LICENSE).
@@ -0,0 +1,18 @@
1
+ workspaceguard/__init__.py,sha256=NW18wN_d4nECbfVhyDOoKEnfdKBwWzLHaoHggvzNhXA,2446
2
+ workspaceguard/circuit_breaker.py,sha256=W9jcZQyzN6VIvVE3NwZtfdaGUOqKON6noWhTaSs8QaM,2562
3
+ workspaceguard/cli.py,sha256=ges4SJ5NcqfnSrzTdCeiiGjPO65p_RE_uwu7ssan6I4,7418
4
+ workspaceguard/config.py,sha256=0IVKamyCckcVUwvVAzoyG81kNd3PlgrYzpKIyduLEpU,6310
5
+ workspaceguard/isolation_guard.py,sha256=Bqholm__h312ac2p5Fkhtbv9OuFNLBA0WDCbjibUp34,7196
6
+ workspaceguard/log.py,sha256=FmYJc9qZsv6HdsS-ijJbWFpZdIZ84vkhfqrQCHNRJA0,1131
7
+ workspaceguard/namespace.py,sha256=SDKAddCa8HWuToiNhO9B5tL9_Bm_quyhQSL95JPgdu4,739
8
+ workspaceguard/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ workspaceguard/types.py,sha256=9aMQcABT6IN0YUY-1OARH9DMWq3PcyrHXi3WWYbMw0A,2529
10
+ workspaceguard/usage.py,sha256=ueilBxUYMp67sLNg9VaBVE74JvOWsNBOiMEigxWUQmM,5357
11
+ workspaceguard/vault.py,sha256=ShUweWCAZxZ526AWTRBuS0t9VfF2vyjecW_QVe3c1OM,5663
12
+ workspaceguard/adapters/__init__.py,sha256=_245FaFzp-CrOwPdKWarZauCW_qStF1tQ_SNtDyDEPA,57
13
+ workspaceguard/adapters/mock.py,sha256=7BNaoP7p8Ammgg5aT17ZZxvDyB8ra2OOXsOqNnHDM1I,1491
14
+ workspaceguard_cli-0.1.1.dist-info/METADATA,sha256=zeiBIZy_ol5DEUmSiGe_WdxYZGAdoc1ksbnTBiolTzc,10288
15
+ workspaceguard_cli-0.1.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
16
+ workspaceguard_cli-0.1.1.dist-info/entry_points.txt,sha256=6vgrd7egZYpsJDoMF5r_xnADAj9ecaIpDYcFBjNq8Gk,59
17
+ workspaceguard_cli-0.1.1.dist-info/licenses/LICENSE,sha256=BfVFjPafHBvDFGiOExHmSA9zx3abipLGkjV1O2MZj9Y,1070
18
+ workspaceguard_cli-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ workspaceguard = workspaceguard.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rudrendu Paul
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.