variantgate 0.9.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.
- variantgate-0.9.0/.gitignore +7 -0
- variantgate-0.9.0/PKG-INFO +293 -0
- variantgate-0.9.0/README.md +280 -0
- variantgate-0.9.0/pyproject.toml +64 -0
- variantgate-0.9.0/src/variantgate/__init__.py +127 -0
- variantgate-0.9.0/src/variantgate/__main__.py +5 -0
- variantgate-0.9.0/src/variantgate/_ed25519.py +92 -0
- variantgate-0.9.0/src/variantgate/_http.py +123 -0
- variantgate-0.9.0/src/variantgate/_version.py +3 -0
- variantgate-0.9.0/src/variantgate/cancel_window.py +93 -0
- variantgate-0.9.0/src/variantgate/canonical.py +73 -0
- variantgate-0.9.0/src/variantgate/cli.py +242 -0
- variantgate-0.9.0/src/variantgate/client.py +298 -0
- variantgate-0.9.0/src/variantgate/errors.py +169 -0
- variantgate-0.9.0/src/variantgate/guard.py +132 -0
- variantgate-0.9.0/src/variantgate/mandate.py +80 -0
- variantgate-0.9.0/src/variantgate/on_behalf.py +57 -0
- variantgate-0.9.0/src/variantgate/plans.py +78 -0
- variantgate-0.9.0/src/variantgate/preview.py +199 -0
- variantgate-0.9.0/src/variantgate/py.typed +0 -0
- variantgate-0.9.0/src/variantgate/receipts.py +212 -0
- variantgate-0.9.0/src/variantgate/run_links.py +39 -0
- variantgate-0.9.0/src/variantgate/runs.py +26 -0
- variantgate-0.9.0/src/variantgate/source_limits.py +122 -0
- variantgate-0.9.0/src/variantgate/sources.py +119 -0
- variantgate-0.9.0/src/variantgate/types.py +132 -0
- variantgate-0.9.0/src/variantgate/webhooks.py +91 -0
- variantgate-0.9.0/tests/cli_support.py +56 -0
- variantgate-0.9.0/tests/receipt_support.py +105 -0
- variantgate-0.9.0/tests/support.py +153 -0
- variantgate-0.9.0/tests/test_cancel_window.py +114 -0
- variantgate-0.9.0/tests/test_canonical_json.py +92 -0
- variantgate-0.9.0/tests/test_changes.py +79 -0
- variantgate-0.9.0/tests/test_cli.py +110 -0
- variantgate-0.9.0/tests/test_cli_mistakes.py +108 -0
- variantgate-0.9.0/tests/test_client.py +207 -0
- variantgate-0.9.0/tests/test_ed25519.py +98 -0
- variantgate-0.9.0/tests/test_guard.py +176 -0
- variantgate-0.9.0/tests/test_mandates.py +82 -0
- variantgate-0.9.0/tests/test_on_behalf.py +67 -0
- variantgate-0.9.0/tests/test_plans.py +80 -0
- variantgate-0.9.0/tests/test_preview.py +106 -0
- variantgate-0.9.0/tests/test_receipt_limits.py +108 -0
- variantgate-0.9.0/tests/test_receipts.py +131 -0
- variantgate-0.9.0/tests/test_run_links.py +55 -0
- variantgate-0.9.0/tests/test_runs.py +151 -0
- variantgate-0.9.0/tests/test_source_limits.py +143 -0
- variantgate-0.9.0/tests/test_sources.py +113 -0
- variantgate-0.9.0/tests/test_waiting.py +104 -0
- variantgate-0.9.0/tests/test_webhooks.py +96 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: variantgate
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Ask a person before your agent acts: a small client and a command-line tool for the VariantGate approvals API.
|
|
5
|
+
Project-URL: Homepage, https://variantgate.com
|
|
6
|
+
Project-URL: Documentation, https://variantgate.com/docs/sdk
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Keywords: ai agents,approvals,human in the loop,variantgate
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# variantgate
|
|
15
|
+
|
|
16
|
+
Ask a person before your agent acts. A small Python client for the [VariantGate](https://variantgate.com) approvals API, and the `variantgate` command for scripts and CI. Standard library only, Python 3.9 or newer, fully typed.
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pip install https://variantgate.com/sdk/variantgate-latest.tar.gz
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Until the package is on PyPI it is served from our site. The PyPI name will be `variantgate`.
|
|
23
|
+
|
|
24
|
+
Set `VARIANTGATE_KEY` to an agent key. `VARIANTGATE_API_URL` defaults to `https://api.variantgate.com`.
|
|
25
|
+
|
|
26
|
+
## Run code only after a yes
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from variantgate import require_approval
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@require_approval(
|
|
33
|
+
"payment.refund",
|
|
34
|
+
lambda order: f"Refund €{order.total} to {order.email} for order {order.id}",
|
|
35
|
+
amount=lambda order: order.total,
|
|
36
|
+
currency="EUR",
|
|
37
|
+
)
|
|
38
|
+
def refund(order):
|
|
39
|
+
return stripe.Refund.create(payment_intent=order.payment_id).id
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Calling `refund(order)` asks, waits for a person (or a standing rule), runs the function only on an approval, and reports afterwards whether it succeeded. Any field can be a value or a function of the decorated function's arguments. `async def` functions work too.
|
|
43
|
+
|
|
44
|
+
The same check as a `with` block:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
with require_approval("deploy.production", "Deploy v2.14 to production") as approval:
|
|
48
|
+
deploy("v2.14")
|
|
49
|
+
approval.note = "deployed v2.14"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## It fails closed
|
|
53
|
+
|
|
54
|
+
Anything but an explicit approval raises, and the code does not run:
|
|
55
|
+
|
|
56
|
+
| What happened | Raised |
|
|
57
|
+
|---|---|
|
|
58
|
+
| Denied, expired, withdrawn, cancelled in its cancel window, still pending or still in its cancel window at the timeout (it is withdrawn), or the workspace or this agent is paused | `NotApprovedError`, with `.decision` |
|
|
59
|
+
| Approved only in a changed version: new wording or a lower amount | `ChangedApprovalError`, a `NotApprovedError`; the outcome is recorded as not done |
|
|
60
|
+
| The key may not ask for this action | `OutOfScopeError`, an `ApprovalApiError` with code `action_out_of_scope` and status 403 |
|
|
61
|
+
| A person stopped the run | `RunStoppedError`, an `ApprovalApiError` with code `run_stopped` and status 409 |
|
|
62
|
+
| The API refused the call or could not be reached | `ApprovalApiError`, with `.code` and `.status` (`network` and 0 when there was no answer) |
|
|
63
|
+
| No key was set | `ConfigurationError` |
|
|
64
|
+
|
|
65
|
+
A revoked or expired key gets an `ApprovalApiError` with code `unauthorized` and status 401. An `OutOfScopeError` means a workspace owner limited the key to other actions, and its message says which. Nothing was stored and nobody was told. Asking again will not help: an owner has to widen the key's scope, or the agent has to use another key.
|
|
66
|
+
|
|
67
|
+
A rule may give approvals a cancel window: the request is `approved` but `allowed` stays false until `acts_at`, and until then anyone in the workspace may cancel it. `wait`, `wait_for_approval` and `guard` wait the window out (it is not bounded by the request's expiry, only by `timeout`), and act only once the API says `allowed`; one still in its window when `timeout` runs out is withdrawn, so it never goes ahead unattended. A cancelled approval comes back `denied`, with `cancelled_by` and `cancelled_at`. `in_cancel_window(decision)` says whether a request is still in its window.
|
|
68
|
+
|
|
69
|
+
All of them are `VariantGateError`s. To act on a changed version, use a `with` block with `accept_changes=True` and do only `approved.decision["approved_summary"]`, for at most `approved.decision["approved_amount"]`. A request still pending when the client stops waiting is withdrawn, so nobody approves it afterwards.
|
|
70
|
+
|
|
71
|
+
## The client
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from variantgate import ApprovalClient, is_allowed
|
|
75
|
+
|
|
76
|
+
approvals = ApprovalClient("billing-bot") # reads the key from the environment
|
|
77
|
+
|
|
78
|
+
asked = approvals.ask("email.send", "Send the March invoice to Acme", wait_seconds=30)
|
|
79
|
+
decision = approvals.wait(asked, timeout=120)
|
|
80
|
+
if is_allowed(decision):
|
|
81
|
+
send_invoice()
|
|
82
|
+
approvals.report_outcome(decision["id"], "succeeded", "message id 42")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
| Method | What it does |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `ask(action, summary, *, amount, currency, details, agent, run, ttl_seconds, wait_seconds)` | Ask, optionally waiting up to 30 seconds |
|
|
88
|
+
| `check(request_id, wait_seconds=0)` | Read the answer, optionally waiting |
|
|
89
|
+
| `wait(decision, timeout=None)` | Wait until it is decided; withdraw it if time runs out |
|
|
90
|
+
| `withdraw(request_id)` | Take back a request nobody has decided |
|
|
91
|
+
| `report_outcome(request_id, outcome, note=None)` | Say whether the approved action succeeded |
|
|
92
|
+
| `guard(act, action, summary, ...)` | Ask, wait, run `act` only on a yes, report the outcome |
|
|
93
|
+
| `require_approval(action, summary, ...)` | The decorator and `with` block, on this client |
|
|
94
|
+
|
|
95
|
+
## Runs
|
|
96
|
+
|
|
97
|
+
Give each request the run it belongs to, one id for one agent session such as a CI job or a conversation, and people see the whole run as one timeline. They can also stop it: everything still waiting in it is denied, and anything the run asks afterwards is refused.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
# Without run=, the client uses $VARIANTGATE_RUN.
|
|
101
|
+
approvals = ApprovalClient("deploy-bot", run=f"deploy-{os.environ['CI_JOB_ID']}")
|
|
102
|
+
approvals.guard(deploy, "deploy.production", "Deploy v2.14", run="deploy-7") # or per request
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
A run id is up to 200 letters, digits, `.`, `_`, `:` and `-`; any other character becomes `_`, and a longer id is cut. Runs belong to the agent key, so the same id under two keys is two runs. In a stopped run, `ask`, `guard`, `wait_for_approval` and `require_approval` raise `RunStoppedError` and nothing is stored, and a request read afterwards has `paused: True` and `pause: "run"`, with `allowed` false whatever its status. Stop asking in that run and tell the person. `variantgate ask` and `run` take `--run ID` and exit 1 in a stopped run.
|
|
106
|
+
|
|
107
|
+
## Run plans: say up front what the run will do
|
|
108
|
+
|
|
109
|
+
At the start of a run, before it reads anything from outside, declare which actions it will take, each at most so many times. A request of the run that the plan does not name, or that uses a step more often than planned, waits for a person whatever the rules say, so a web page or an email the agent reads later cannot talk it into something its task never needed. The plan is locked once declared, and it never approves anything.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
approvals = ApprovalClient("support-bot", run="ticket-4411")
|
|
113
|
+
approvals.declare_plan("Answer ticket 4411", ["crm.read", ("email.send", 1), "kb.*"])
|
|
114
|
+
plan = approvals.get_plan() # steps with "used", or None
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
A step is an action or a family such as `kb.*`, as a string, an `(action, max)` tuple or a `{"action": ..., "max": ...}` dict; up to 20 steps, `max` from 1 to 1000. Declaring the same plan again changes nothing; a different one raises `PlanLockedError` (409 `plan_locked`). `declare_plan` returns None when the server is older than run plans; the run then carries on under the rules alone. A plan needs a run: pass `run=` or give the client one. People see the plan on the run's page and, on each held request, why it was off the plan.
|
|
118
|
+
|
|
119
|
+
### Whom the run works for
|
|
120
|
+
|
|
121
|
+
A support agent works for one customer at a time, but its keys can email, refund and look up every customer. Declare that person at the start of the run, before it reads the ticket:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
approvals.declare_on_behalf(
|
|
125
|
+
["ana@example.com", "cus_8812", "DE89 3704 0044 0532 0130 00"],
|
|
126
|
+
label="Ana Lopez, ticket 4411",
|
|
127
|
+
)
|
|
128
|
+
lock = approvals.get_on_behalf() # or None
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
From then on, a request of the run whose details send to, pay or look up anyone else (another email address, phone number, IBAN or account number, or another id in a field such as `customer_id`), or a recipient that cannot be read, waits for a person whatever the rules say. Up to 10 parties of up to 200 characters, and a label of up to 100. The lock is fixed once declared: the same lock again changes nothing, another raises `OnBehalfLockedError` (409 `on_behalf_locked`). Sub-agent runs answer to the lock above them too. `declare_on_behalf` returns None when the server is older than these locks.
|
|
132
|
+
|
|
133
|
+
### Sub-agent runs
|
|
134
|
+
|
|
135
|
+
When an agent hands part of its task to a sub-agent, link the sub-agent's run below its own:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
approvals.link_run("ticket-4411.research", "ticket-4411")
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The family is then weighed as one: what the sub-agent read counts for the trifecta guard on the parent's sends, each request answers to its own run's plan and every plan above it, and stopping a run stops the runs below it. Linking the same parent again changes nothing; another parent raises `RunLinkedError` (409 `run_linked`). A loop, more than 5 runs deep or more than 100 in a family is refused with 422. `link_run` returns None when the server is older than sub-agent runs. Both runs belong to the same key.
|
|
142
|
+
|
|
143
|
+
## Mandates: ask once for a bounded run
|
|
144
|
+
|
|
145
|
+
Before a task starts, ask for what it will need: "up to 10 refunds, each at most EUR 40, EUR 200 in all, for the next hour, in this run". A workspace owner grants it once in the inbox, and each step the agent then asks for in that run is answered by the grant until its uses, total or time run out; after that, steps wait for a person as usual. Every deny rule, hold and pause still wins.
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
answer = approvals.request_mandate(
|
|
149
|
+
"refund.create",
|
|
150
|
+
"Refund the damaged items in order 1042",
|
|
151
|
+
run="chat-81",
|
|
152
|
+
uses=10,
|
|
153
|
+
minutes=60,
|
|
154
|
+
amount="40",
|
|
155
|
+
currency="EUR", # the most one step may move
|
|
156
|
+
total="200", # the most all steps may move together
|
|
157
|
+
)
|
|
158
|
+
if answer.granted:
|
|
159
|
+
approvals.guard(
|
|
160
|
+
refund,
|
|
161
|
+
"refund.create",
|
|
162
|
+
"Refund item 1 of order 1042",
|
|
163
|
+
amount="12.50",
|
|
164
|
+
currency="EUR",
|
|
165
|
+
run="chat-81",
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The request that asks never has `allowed` true; `answer.granted` is true only when an owner granted it. Keep asking for each step with `ask` or `guard`. A mandate needs a run, an action without `*`, 1 to 100 uses and 5 to 480 minutes; `total` (in `total_currency`, or else `currency`) must be at least `amount`. A mandate still pending at `timeout` is withdrawn.
|
|
170
|
+
|
|
171
|
+
## The command line
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
variantgate run --action deploy.production --summary "Deploy v2.14" -- ./deploy.sh v2.14
|
|
175
|
+
variantgate ask --action db.migrate --summary "Run the March migration" --timeout 600
|
|
176
|
+
variantgate withdraw REQUEST_ID
|
|
177
|
+
variantgate outcome REQUEST_ID succeeded --note "migrated 12 tables"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Exit codes: 0 approved, 1 not approved, 2 a mistake or an unreachable API, 3 approved only with changes (`run` never runs its command then). `python -m variantgate` does the same.
|
|
181
|
+
|
|
182
|
+
## Checking a webhook
|
|
183
|
+
|
|
184
|
+
A workspace on Pro or higher can send signed webhooks to your own systems. `verify_webhook` checks one the Standard Webhooks way, with a constant-time compare, refuses a timestamp more than five minutes from now, and returns the event. Pass the body exactly as it arrived.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
import os
|
|
188
|
+
|
|
189
|
+
from flask import Flask, request
|
|
190
|
+
from variantgate import WebhookVerificationError, verify_webhook
|
|
191
|
+
|
|
192
|
+
app = Flask(__name__)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@app.post("/variantgate")
|
|
196
|
+
def variantgate_webhook():
|
|
197
|
+
try:
|
|
198
|
+
event = verify_webhook(
|
|
199
|
+
os.environ["VARIANTGATE_WEBHOOK_SECRET"], request.headers, request.get_data()
|
|
200
|
+
)
|
|
201
|
+
except WebhookVerificationError:
|
|
202
|
+
return "", 400
|
|
203
|
+
if event["type"] == "request.approved":
|
|
204
|
+
resume_agent(event["data"]["request_id"])
|
|
205
|
+
return "", 204
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
A webhook is a notification, never a permission: before acting, the agent still reads its request with `client.check(id)` and acts only when `allowed` is true.
|
|
209
|
+
|
|
210
|
+
## Sources: show what the agent read
|
|
211
|
+
|
|
212
|
+
An agent that reads an email, a web page or a ticket can be steered by text inside it. Have your code (not the model) list what the agent read with the request, so the person deciding sees that an email arrived just before the agent asked to pay someone:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from variantgate import Sources, require_approval
|
|
216
|
+
|
|
217
|
+
read = Sources()
|
|
218
|
+
read.user("Pay the Acme invoice") # the person's instruction: trusted
|
|
219
|
+
read.email("Email from billing@acme.com", email.text) # untrusted
|
|
220
|
+
read.web(page.url, page.text) # untrusted
|
|
221
|
+
read.tool("orders.lookup", json.dumps(row), trusted=True) # your own lookup
|
|
222
|
+
|
|
223
|
+
with require_approval(
|
|
224
|
+
"payment.send", "Pay Acme 1,200.00 EUR", amount="1200.00", currency="EUR", sources=read.list()
|
|
225
|
+
):
|
|
226
|
+
pay(invoice)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`user`, `email`, `web`, `document`, `ticket`, `chat`, `tool`, `agent` and `other` each take a label and, optionally, the part of the text that led to the request. Everything but `user` is untrusted unless you pass `trusted=True`; vouch only for text no outsider or model could have written. When the agent read anything untrusted, no `allow` rule approves the request on its own: a person decides, and sees which values in `details` (emails, hosts, account numbers) came from untrusted text and any untrusted text that reads like orders to an AI. Untrusted input never makes a request easier to approve.
|
|
230
|
+
|
|
231
|
+
Labels are cut to 200 characters and excerpts to 2,000 (never splitting a character), ending in `…`. A blank label becomes the kind's name. A request lists at most 10 inputs. With more, `list()` keeps 9 as they are, in the order read, choosing untrusted inputs with text first, then trusted ones with text (such as the person's instruction), then the rest, newest first within each group. The others are folded into one `other` entry, "N more inputs", whose excerpt joins their texts, untrusted first, each after its label, cut to 2,000 characters; it is untrusted if any of them was. So up to 9 inputs with text keep their text whole, untrusted text before trusted; past that, text in the folded entry may be cut. All excerpts together are kept to 32,000 UTF-8 bytes, well inside the API's 64 KB body limit: when they would take more, trusted excerpts are shortened first, then untrusted ones from the oldest, each cut between characters and ending in `…` (one with no room left is dropped). `sources=` also takes plain dicts (`{"kind": ..., "label": ..., "excerpt": ..., "trust": ...}`), and works with `ask`, `wait_for_approval`, `guard` and `require_approval`. The agent's own reads of a request never show the sources back.
|
|
232
|
+
|
|
233
|
+
## Preview: show what the action will do
|
|
234
|
+
|
|
235
|
+
A summary is the agent's description of an action. A preview is the thing itself, made by your code before it asks: the email as it will go out, the diff, the SQL with the row count a dry run found, or the records the change touches. The person deciding sees it next to checks that compare it with the rest of the request, such as a preview sending to an address the details do not name, a row count far from the one in the summary, or a diff that edits CI or agent settings. While any check finds something, no `allow` rule approves the request on its own.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from variantgate import require_approval
|
|
239
|
+
|
|
240
|
+
statement = "DELETE FROM users WHERE email LIKE '%@test.example'"
|
|
241
|
+
preview = {"kind": "sql", "statement": statement, "rows_affected": 3} # from a rolled-back dry run
|
|
242
|
+
|
|
243
|
+
with require_approval("database.delete", "Delete the 3 test accounts", preview=preview):
|
|
244
|
+
db.execute(statement)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The other kinds:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
{"kind": "email", "to": ["ana@example.com"], "subject": "Invoice 1042", "body": rendered}
|
|
251
|
+
{"kind": "diff", "patch": git_diff_output}
|
|
252
|
+
{"kind": "records", "columns": ["id", "email"], "rows": first_fifty, "total": 412}
|
|
253
|
+
{"kind": "text", "title": "Post to #general", "body": message}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`EmailPreview`, `DiffPreview`, `SqlPreview`, `RecordsPreview` and `TextPreview` type them. `ask` checks the preview with `preview_problem` before sending and raises `ApprovalApiError` (`invalid_request`) when it does not fit; a preview is never cut, since a shortened diff would show less than the action does. The limits: email `to` 1 to 50 addresses, `cc` and `bcc` up to 50 each, subject 500 characters, body 20,000; patch 60,000; statement and plan 10,000 each; records 1 to 20 columns and at most 50 rows, with `total` for the full count. The whole request must still fit the API's 64 KB body limit. The preview is the agent's own claim: it helps a person see what they approve, and it never approves anything. API versions from before previews refuse the field. More: https://variantgate.com/docs/consequence-preview
|
|
257
|
+
|
|
258
|
+
## Check a receipt in your tool
|
|
259
|
+
|
|
260
|
+
When a person approves a request, the agent's read of it carries `receipt`. The tool that does the work can check it offline, with the keys from `GET https://api.variantgate.com/v1/receipt-keys`, before it moves anything:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from variantgate import ReceiptError, verify_receipt
|
|
264
|
+
|
|
265
|
+
used = set() # request ids already acted on; keep it somewhere lasting
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def refund(receipt, order, keys):
|
|
269
|
+
try:
|
|
270
|
+
verify_receipt(
|
|
271
|
+
receipt,
|
|
272
|
+
keys=keys,
|
|
273
|
+
workspace=WORKSPACE_ID,
|
|
274
|
+
action="payment.refund",
|
|
275
|
+
details=order.details,
|
|
276
|
+
amount=order.total,
|
|
277
|
+
currency="EUR",
|
|
278
|
+
seen=used,
|
|
279
|
+
)
|
|
280
|
+
except ReceiptError as refused:
|
|
281
|
+
return f"not approved: {refused}"
|
|
282
|
+
return stripe.Refund.create(payment_intent=order.payment_id).id
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
It refuses a receipt that is not signed by a listed key, is for another workspace, action or agent key (`agent_key=`), carries other `details` than were approved, moves more than the approved amount, is older than five minutes, or was used before. Pass the amount as a `str`, `int` or `Decimal`, never a float, and keep money and long numbers in `details` as strings.
|
|
286
|
+
|
|
287
|
+
## Developing
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
uv run pytest
|
|
291
|
+
uv run coverage run -m pytest && uv run coverage report
|
|
292
|
+
uv run mypy && uv run ruff check && uv run ruff format --check
|
|
293
|
+
```
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# variantgate
|
|
2
|
+
|
|
3
|
+
Ask a person before your agent acts. A small Python client for the [VariantGate](https://variantgate.com) approvals API, and the `variantgate` command for scripts and CI. Standard library only, Python 3.9 or newer, fully typed.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pip install https://variantgate.com/sdk/variantgate-latest.tar.gz
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Until the package is on PyPI it is served from our site. The PyPI name will be `variantgate`.
|
|
10
|
+
|
|
11
|
+
Set `VARIANTGATE_KEY` to an agent key. `VARIANTGATE_API_URL` defaults to `https://api.variantgate.com`.
|
|
12
|
+
|
|
13
|
+
## Run code only after a yes
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from variantgate import require_approval
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@require_approval(
|
|
20
|
+
"payment.refund",
|
|
21
|
+
lambda order: f"Refund €{order.total} to {order.email} for order {order.id}",
|
|
22
|
+
amount=lambda order: order.total,
|
|
23
|
+
currency="EUR",
|
|
24
|
+
)
|
|
25
|
+
def refund(order):
|
|
26
|
+
return stripe.Refund.create(payment_intent=order.payment_id).id
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Calling `refund(order)` asks, waits for a person (or a standing rule), runs the function only on an approval, and reports afterwards whether it succeeded. Any field can be a value or a function of the decorated function's arguments. `async def` functions work too.
|
|
30
|
+
|
|
31
|
+
The same check as a `with` block:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
with require_approval("deploy.production", "Deploy v2.14 to production") as approval:
|
|
35
|
+
deploy("v2.14")
|
|
36
|
+
approval.note = "deployed v2.14"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## It fails closed
|
|
40
|
+
|
|
41
|
+
Anything but an explicit approval raises, and the code does not run:
|
|
42
|
+
|
|
43
|
+
| What happened | Raised |
|
|
44
|
+
|---|---|
|
|
45
|
+
| Denied, expired, withdrawn, cancelled in its cancel window, still pending or still in its cancel window at the timeout (it is withdrawn), or the workspace or this agent is paused | `NotApprovedError`, with `.decision` |
|
|
46
|
+
| Approved only in a changed version: new wording or a lower amount | `ChangedApprovalError`, a `NotApprovedError`; the outcome is recorded as not done |
|
|
47
|
+
| The key may not ask for this action | `OutOfScopeError`, an `ApprovalApiError` with code `action_out_of_scope` and status 403 |
|
|
48
|
+
| A person stopped the run | `RunStoppedError`, an `ApprovalApiError` with code `run_stopped` and status 409 |
|
|
49
|
+
| The API refused the call or could not be reached | `ApprovalApiError`, with `.code` and `.status` (`network` and 0 when there was no answer) |
|
|
50
|
+
| No key was set | `ConfigurationError` |
|
|
51
|
+
|
|
52
|
+
A revoked or expired key gets an `ApprovalApiError` with code `unauthorized` and status 401. An `OutOfScopeError` means a workspace owner limited the key to other actions, and its message says which. Nothing was stored and nobody was told. Asking again will not help: an owner has to widen the key's scope, or the agent has to use another key.
|
|
53
|
+
|
|
54
|
+
A rule may give approvals a cancel window: the request is `approved` but `allowed` stays false until `acts_at`, and until then anyone in the workspace may cancel it. `wait`, `wait_for_approval` and `guard` wait the window out (it is not bounded by the request's expiry, only by `timeout`), and act only once the API says `allowed`; one still in its window when `timeout` runs out is withdrawn, so it never goes ahead unattended. A cancelled approval comes back `denied`, with `cancelled_by` and `cancelled_at`. `in_cancel_window(decision)` says whether a request is still in its window.
|
|
55
|
+
|
|
56
|
+
All of them are `VariantGateError`s. To act on a changed version, use a `with` block with `accept_changes=True` and do only `approved.decision["approved_summary"]`, for at most `approved.decision["approved_amount"]`. A request still pending when the client stops waiting is withdrawn, so nobody approves it afterwards.
|
|
57
|
+
|
|
58
|
+
## The client
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from variantgate import ApprovalClient, is_allowed
|
|
62
|
+
|
|
63
|
+
approvals = ApprovalClient("billing-bot") # reads the key from the environment
|
|
64
|
+
|
|
65
|
+
asked = approvals.ask("email.send", "Send the March invoice to Acme", wait_seconds=30)
|
|
66
|
+
decision = approvals.wait(asked, timeout=120)
|
|
67
|
+
if is_allowed(decision):
|
|
68
|
+
send_invoice()
|
|
69
|
+
approvals.report_outcome(decision["id"], "succeeded", "message id 42")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| Method | What it does |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `ask(action, summary, *, amount, currency, details, agent, run, ttl_seconds, wait_seconds)` | Ask, optionally waiting up to 30 seconds |
|
|
75
|
+
| `check(request_id, wait_seconds=0)` | Read the answer, optionally waiting |
|
|
76
|
+
| `wait(decision, timeout=None)` | Wait until it is decided; withdraw it if time runs out |
|
|
77
|
+
| `withdraw(request_id)` | Take back a request nobody has decided |
|
|
78
|
+
| `report_outcome(request_id, outcome, note=None)` | Say whether the approved action succeeded |
|
|
79
|
+
| `guard(act, action, summary, ...)` | Ask, wait, run `act` only on a yes, report the outcome |
|
|
80
|
+
| `require_approval(action, summary, ...)` | The decorator and `with` block, on this client |
|
|
81
|
+
|
|
82
|
+
## Runs
|
|
83
|
+
|
|
84
|
+
Give each request the run it belongs to, one id for one agent session such as a CI job or a conversation, and people see the whole run as one timeline. They can also stop it: everything still waiting in it is denied, and anything the run asks afterwards is refused.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
# Without run=, the client uses $VARIANTGATE_RUN.
|
|
88
|
+
approvals = ApprovalClient("deploy-bot", run=f"deploy-{os.environ['CI_JOB_ID']}")
|
|
89
|
+
approvals.guard(deploy, "deploy.production", "Deploy v2.14", run="deploy-7") # or per request
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A run id is up to 200 letters, digits, `.`, `_`, `:` and `-`; any other character becomes `_`, and a longer id is cut. Runs belong to the agent key, so the same id under two keys is two runs. In a stopped run, `ask`, `guard`, `wait_for_approval` and `require_approval` raise `RunStoppedError` and nothing is stored, and a request read afterwards has `paused: True` and `pause: "run"`, with `allowed` false whatever its status. Stop asking in that run and tell the person. `variantgate ask` and `run` take `--run ID` and exit 1 in a stopped run.
|
|
93
|
+
|
|
94
|
+
## Run plans: say up front what the run will do
|
|
95
|
+
|
|
96
|
+
At the start of a run, before it reads anything from outside, declare which actions it will take, each at most so many times. A request of the run that the plan does not name, or that uses a step more often than planned, waits for a person whatever the rules say, so a web page or an email the agent reads later cannot talk it into something its task never needed. The plan is locked once declared, and it never approves anything.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
approvals = ApprovalClient("support-bot", run="ticket-4411")
|
|
100
|
+
approvals.declare_plan("Answer ticket 4411", ["crm.read", ("email.send", 1), "kb.*"])
|
|
101
|
+
plan = approvals.get_plan() # steps with "used", or None
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A step is an action or a family such as `kb.*`, as a string, an `(action, max)` tuple or a `{"action": ..., "max": ...}` dict; up to 20 steps, `max` from 1 to 1000. Declaring the same plan again changes nothing; a different one raises `PlanLockedError` (409 `plan_locked`). `declare_plan` returns None when the server is older than run plans; the run then carries on under the rules alone. A plan needs a run: pass `run=` or give the client one. People see the plan on the run's page and, on each held request, why it was off the plan.
|
|
105
|
+
|
|
106
|
+
### Whom the run works for
|
|
107
|
+
|
|
108
|
+
A support agent works for one customer at a time, but its keys can email, refund and look up every customer. Declare that person at the start of the run, before it reads the ticket:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
approvals.declare_on_behalf(
|
|
112
|
+
["ana@example.com", "cus_8812", "DE89 3704 0044 0532 0130 00"],
|
|
113
|
+
label="Ana Lopez, ticket 4411",
|
|
114
|
+
)
|
|
115
|
+
lock = approvals.get_on_behalf() # or None
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
From then on, a request of the run whose details send to, pay or look up anyone else (another email address, phone number, IBAN or account number, or another id in a field such as `customer_id`), or a recipient that cannot be read, waits for a person whatever the rules say. Up to 10 parties of up to 200 characters, and a label of up to 100. The lock is fixed once declared: the same lock again changes nothing, another raises `OnBehalfLockedError` (409 `on_behalf_locked`). Sub-agent runs answer to the lock above them too. `declare_on_behalf` returns None when the server is older than these locks.
|
|
119
|
+
|
|
120
|
+
### Sub-agent runs
|
|
121
|
+
|
|
122
|
+
When an agent hands part of its task to a sub-agent, link the sub-agent's run below its own:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
approvals.link_run("ticket-4411.research", "ticket-4411")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The family is then weighed as one: what the sub-agent read counts for the trifecta guard on the parent's sends, each request answers to its own run's plan and every plan above it, and stopping a run stops the runs below it. Linking the same parent again changes nothing; another parent raises `RunLinkedError` (409 `run_linked`). A loop, more than 5 runs deep or more than 100 in a family is refused with 422. `link_run` returns None when the server is older than sub-agent runs. Both runs belong to the same key.
|
|
129
|
+
|
|
130
|
+
## Mandates: ask once for a bounded run
|
|
131
|
+
|
|
132
|
+
Before a task starts, ask for what it will need: "up to 10 refunds, each at most EUR 40, EUR 200 in all, for the next hour, in this run". A workspace owner grants it once in the inbox, and each step the agent then asks for in that run is answered by the grant until its uses, total or time run out; after that, steps wait for a person as usual. Every deny rule, hold and pause still wins.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
answer = approvals.request_mandate(
|
|
136
|
+
"refund.create",
|
|
137
|
+
"Refund the damaged items in order 1042",
|
|
138
|
+
run="chat-81",
|
|
139
|
+
uses=10,
|
|
140
|
+
minutes=60,
|
|
141
|
+
amount="40",
|
|
142
|
+
currency="EUR", # the most one step may move
|
|
143
|
+
total="200", # the most all steps may move together
|
|
144
|
+
)
|
|
145
|
+
if answer.granted:
|
|
146
|
+
approvals.guard(
|
|
147
|
+
refund,
|
|
148
|
+
"refund.create",
|
|
149
|
+
"Refund item 1 of order 1042",
|
|
150
|
+
amount="12.50",
|
|
151
|
+
currency="EUR",
|
|
152
|
+
run="chat-81",
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The request that asks never has `allowed` true; `answer.granted` is true only when an owner granted it. Keep asking for each step with `ask` or `guard`. A mandate needs a run, an action without `*`, 1 to 100 uses and 5 to 480 minutes; `total` (in `total_currency`, or else `currency`) must be at least `amount`. A mandate still pending at `timeout` is withdrawn.
|
|
157
|
+
|
|
158
|
+
## The command line
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
variantgate run --action deploy.production --summary "Deploy v2.14" -- ./deploy.sh v2.14
|
|
162
|
+
variantgate ask --action db.migrate --summary "Run the March migration" --timeout 600
|
|
163
|
+
variantgate withdraw REQUEST_ID
|
|
164
|
+
variantgate outcome REQUEST_ID succeeded --note "migrated 12 tables"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Exit codes: 0 approved, 1 not approved, 2 a mistake or an unreachable API, 3 approved only with changes (`run` never runs its command then). `python -m variantgate` does the same.
|
|
168
|
+
|
|
169
|
+
## Checking a webhook
|
|
170
|
+
|
|
171
|
+
A workspace on Pro or higher can send signed webhooks to your own systems. `verify_webhook` checks one the Standard Webhooks way, with a constant-time compare, refuses a timestamp more than five minutes from now, and returns the event. Pass the body exactly as it arrived.
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
import os
|
|
175
|
+
|
|
176
|
+
from flask import Flask, request
|
|
177
|
+
from variantgate import WebhookVerificationError, verify_webhook
|
|
178
|
+
|
|
179
|
+
app = Flask(__name__)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@app.post("/variantgate")
|
|
183
|
+
def variantgate_webhook():
|
|
184
|
+
try:
|
|
185
|
+
event = verify_webhook(
|
|
186
|
+
os.environ["VARIANTGATE_WEBHOOK_SECRET"], request.headers, request.get_data()
|
|
187
|
+
)
|
|
188
|
+
except WebhookVerificationError:
|
|
189
|
+
return "", 400
|
|
190
|
+
if event["type"] == "request.approved":
|
|
191
|
+
resume_agent(event["data"]["request_id"])
|
|
192
|
+
return "", 204
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
A webhook is a notification, never a permission: before acting, the agent still reads its request with `client.check(id)` and acts only when `allowed` is true.
|
|
196
|
+
|
|
197
|
+
## Sources: show what the agent read
|
|
198
|
+
|
|
199
|
+
An agent that reads an email, a web page or a ticket can be steered by text inside it. Have your code (not the model) list what the agent read with the request, so the person deciding sees that an email arrived just before the agent asked to pay someone:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from variantgate import Sources, require_approval
|
|
203
|
+
|
|
204
|
+
read = Sources()
|
|
205
|
+
read.user("Pay the Acme invoice") # the person's instruction: trusted
|
|
206
|
+
read.email("Email from billing@acme.com", email.text) # untrusted
|
|
207
|
+
read.web(page.url, page.text) # untrusted
|
|
208
|
+
read.tool("orders.lookup", json.dumps(row), trusted=True) # your own lookup
|
|
209
|
+
|
|
210
|
+
with require_approval(
|
|
211
|
+
"payment.send", "Pay Acme 1,200.00 EUR", amount="1200.00", currency="EUR", sources=read.list()
|
|
212
|
+
):
|
|
213
|
+
pay(invoice)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`user`, `email`, `web`, `document`, `ticket`, `chat`, `tool`, `agent` and `other` each take a label and, optionally, the part of the text that led to the request. Everything but `user` is untrusted unless you pass `trusted=True`; vouch only for text no outsider or model could have written. When the agent read anything untrusted, no `allow` rule approves the request on its own: a person decides, and sees which values in `details` (emails, hosts, account numbers) came from untrusted text and any untrusted text that reads like orders to an AI. Untrusted input never makes a request easier to approve.
|
|
217
|
+
|
|
218
|
+
Labels are cut to 200 characters and excerpts to 2,000 (never splitting a character), ending in `…`. A blank label becomes the kind's name. A request lists at most 10 inputs. With more, `list()` keeps 9 as they are, in the order read, choosing untrusted inputs with text first, then trusted ones with text (such as the person's instruction), then the rest, newest first within each group. The others are folded into one `other` entry, "N more inputs", whose excerpt joins their texts, untrusted first, each after its label, cut to 2,000 characters; it is untrusted if any of them was. So up to 9 inputs with text keep their text whole, untrusted text before trusted; past that, text in the folded entry may be cut. All excerpts together are kept to 32,000 UTF-8 bytes, well inside the API's 64 KB body limit: when they would take more, trusted excerpts are shortened first, then untrusted ones from the oldest, each cut between characters and ending in `…` (one with no room left is dropped). `sources=` also takes plain dicts (`{"kind": ..., "label": ..., "excerpt": ..., "trust": ...}`), and works with `ask`, `wait_for_approval`, `guard` and `require_approval`. The agent's own reads of a request never show the sources back.
|
|
219
|
+
|
|
220
|
+
## Preview: show what the action will do
|
|
221
|
+
|
|
222
|
+
A summary is the agent's description of an action. A preview is the thing itself, made by your code before it asks: the email as it will go out, the diff, the SQL with the row count a dry run found, or the records the change touches. The person deciding sees it next to checks that compare it with the rest of the request, such as a preview sending to an address the details do not name, a row count far from the one in the summary, or a diff that edits CI or agent settings. While any check finds something, no `allow` rule approves the request on its own.
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from variantgate import require_approval
|
|
226
|
+
|
|
227
|
+
statement = "DELETE FROM users WHERE email LIKE '%@test.example'"
|
|
228
|
+
preview = {"kind": "sql", "statement": statement, "rows_affected": 3} # from a rolled-back dry run
|
|
229
|
+
|
|
230
|
+
with require_approval("database.delete", "Delete the 3 test accounts", preview=preview):
|
|
231
|
+
db.execute(statement)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The other kinds:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
{"kind": "email", "to": ["ana@example.com"], "subject": "Invoice 1042", "body": rendered}
|
|
238
|
+
{"kind": "diff", "patch": git_diff_output}
|
|
239
|
+
{"kind": "records", "columns": ["id", "email"], "rows": first_fifty, "total": 412}
|
|
240
|
+
{"kind": "text", "title": "Post to #general", "body": message}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`EmailPreview`, `DiffPreview`, `SqlPreview`, `RecordsPreview` and `TextPreview` type them. `ask` checks the preview with `preview_problem` before sending and raises `ApprovalApiError` (`invalid_request`) when it does not fit; a preview is never cut, since a shortened diff would show less than the action does. The limits: email `to` 1 to 50 addresses, `cc` and `bcc` up to 50 each, subject 500 characters, body 20,000; patch 60,000; statement and plan 10,000 each; records 1 to 20 columns and at most 50 rows, with `total` for the full count. The whole request must still fit the API's 64 KB body limit. The preview is the agent's own claim: it helps a person see what they approve, and it never approves anything. API versions from before previews refuse the field. More: https://variantgate.com/docs/consequence-preview
|
|
244
|
+
|
|
245
|
+
## Check a receipt in your tool
|
|
246
|
+
|
|
247
|
+
When a person approves a request, the agent's read of it carries `receipt`. The tool that does the work can check it offline, with the keys from `GET https://api.variantgate.com/v1/receipt-keys`, before it moves anything:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from variantgate import ReceiptError, verify_receipt
|
|
251
|
+
|
|
252
|
+
used = set() # request ids already acted on; keep it somewhere lasting
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def refund(receipt, order, keys):
|
|
256
|
+
try:
|
|
257
|
+
verify_receipt(
|
|
258
|
+
receipt,
|
|
259
|
+
keys=keys,
|
|
260
|
+
workspace=WORKSPACE_ID,
|
|
261
|
+
action="payment.refund",
|
|
262
|
+
details=order.details,
|
|
263
|
+
amount=order.total,
|
|
264
|
+
currency="EUR",
|
|
265
|
+
seen=used,
|
|
266
|
+
)
|
|
267
|
+
except ReceiptError as refused:
|
|
268
|
+
return f"not approved: {refused}"
|
|
269
|
+
return stripe.Refund.create(payment_intent=order.payment_id).id
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
It refuses a receipt that is not signed by a listed key, is for another workspace, action or agent key (`agent_key=`), carries other `details` than were approved, moves more than the approved amount, is older than five minutes, or was used before. Pass the amount as a `str`, `int` or `Decimal`, never a float, and keep money and long numbers in `details` as strings.
|
|
273
|
+
|
|
274
|
+
## Developing
|
|
275
|
+
|
|
276
|
+
```sh
|
|
277
|
+
uv run pytest
|
|
278
|
+
uv run coverage run -m pytest && uv run coverage report
|
|
279
|
+
uv run mypy && uv run ruff check && uv run ruff format --check
|
|
280
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "variantgate"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Ask a person before your agent acts: a small client and a command-line tool for the VariantGate approvals API."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = []
|
|
13
|
+
keywords = ["ai agents", "approvals", "human in the loop", "variantgate"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Typing :: Typed",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://variantgate.com"
|
|
21
|
+
Documentation = "https://variantgate.com/docs/sdk"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
variantgate = "variantgate.cli:entry"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.version]
|
|
27
|
+
path = "src/variantgate/_version.py"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.sdist]
|
|
30
|
+
include = ["src", "tests", "README.md", "pyproject.toml"]
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/variantgate"]
|
|
34
|
+
|
|
35
|
+
[dependency-groups]
|
|
36
|
+
dev = ["coverage>=7.6", "mypy>=1.15", "pytest>=8.3", "pytest-timeout>=2.3", "ruff>=0.11"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
addopts = ["--strict-markers"]
|
|
41
|
+
# A test that needs longer than this is doing too much.
|
|
42
|
+
timeout = 2
|
|
43
|
+
|
|
44
|
+
[tool.coverage.run]
|
|
45
|
+
source = ["variantgate"]
|
|
46
|
+
branch = true
|
|
47
|
+
|
|
48
|
+
[tool.coverage.report]
|
|
49
|
+
fail_under = 100
|
|
50
|
+
show_missing = true
|
|
51
|
+
exclude_also = ["if TYPE_CHECKING:", "if __name__ == .__main__.:"]
|
|
52
|
+
|
|
53
|
+
[tool.mypy]
|
|
54
|
+
strict = true
|
|
55
|
+
files = ["src", "tests"]
|
|
56
|
+
mypy_path = "src"
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
target-version = "py39"
|
|
60
|
+
line-length = 100
|
|
61
|
+
src = ["src", "tests"]
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF", "PT", "N"]
|