warrantgen 0.1.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.
Files changed (42) hide show
  1. warrantgen-0.1.0/.github/workflows/publish.yml +25 -0
  2. warrantgen-0.1.0/.github/workflows/tests.yml +27 -0
  3. warrantgen-0.1.0/.gitignore +7 -0
  4. warrantgen-0.1.0/LICENSE +202 -0
  5. warrantgen-0.1.0/PKG-INFO +167 -0
  6. warrantgen-0.1.0/README.md +153 -0
  7. warrantgen-0.1.0/UPSTREAM.md +73 -0
  8. warrantgen-0.1.0/docs/drawerrr-submission.md +122 -0
  9. warrantgen-0.1.0/examples/demo/README.md +26 -0
  10. warrantgen-0.1.0/examples/demo/agent.py +131 -0
  11. warrantgen-0.1.0/examples/demo/draft.yaml +13 -0
  12. warrantgen-0.1.0/examples/refund-agent/README.md +84 -0
  13. warrantgen-0.1.0/examples/refund-agent/support_agent.py +262 -0
  14. warrantgen-0.1.0/examples/seo-agent/README.md +51 -0
  15. warrantgen-0.1.0/examples/seo-agent/cli_roundtrip.py +85 -0
  16. warrantgen-0.1.0/examples/seo-agent/evaluate.py +57 -0
  17. warrantgen-0.1.0/examples/seo-agent/record_runs.py +115 -0
  18. warrantgen-0.1.0/examples/seo-agent/traces.jsonl +192 -0
  19. warrantgen-0.1.0/examples/seo-agent/write-step.example.yaml +26 -0
  20. warrantgen-0.1.0/pyproject.toml +24 -0
  21. warrantgen-0.1.0/src/warrantgen/__init__.py +5 -0
  22. warrantgen-0.1.0/src/warrantgen/chain.py +98 -0
  23. warrantgen-0.1.0/src/warrantgen/cli.py +180 -0
  24. warrantgen-0.1.0/src/warrantgen/emit.py +64 -0
  25. warrantgen-0.1.0/src/warrantgen/infer.py +202 -0
  26. warrantgen-0.1.0/src/warrantgen/minting.py +74 -0
  27. warrantgen-0.1.0/src/warrantgen/reconcile.py +122 -0
  28. warrantgen-0.1.0/src/warrantgen/record_langchain.py +51 -0
  29. warrantgen-0.1.0/src/warrantgen/record_temporal.py +28 -0
  30. warrantgen-0.1.0/src/warrantgen/testgen.py +134 -0
  31. warrantgen-0.1.0/tests/test_audit_input.py +29 -0
  32. warrantgen-0.1.0/tests/test_chain.py +116 -0
  33. warrantgen-0.1.0/tests/test_cli.py +58 -0
  34. warrantgen-0.1.0/tests/test_demo.py +27 -0
  35. warrantgen-0.1.0/tests/test_emit.py +37 -0
  36. warrantgen-0.1.0/tests/test_infer.py +140 -0
  37. warrantgen-0.1.0/tests/test_reconcile.py +83 -0
  38. warrantgen-0.1.0/tests/test_record_langchain.py +107 -0
  39. warrantgen-0.1.0/tests/test_record_temporal.py +29 -0
  40. warrantgen-0.1.0/tests/test_refund_demo.py +30 -0
  41. warrantgen-0.1.0/tests/test_testgen.py +90 -0
  42. warrantgen-0.1.0/uv.lock +1568 -0
@@ -0,0 +1,25 @@
1
+ name: publish
2
+
3
+ # Push a v* tag to test, build and upload to PyPI. PyPI trusts this workflow (trusted publishing), so no token is stored.
4
+ on:
5
+ push:
6
+ tags: ["v*"]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ pypi:
13
+ runs-on: ubuntu-latest
14
+ environment: pypi
15
+ permissions:
16
+ id-token: write # lets uv publish prove to PyPI that this workflow is the trusted publisher
17
+ steps:
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ with:
20
+ persist-credentials: false
21
+ - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
22
+ - run: uv sync --locked
23
+ - run: uv run pytest -q
24
+ - run: uv build
25
+ - run: uv publish
@@ -0,0 +1,27 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ pytest:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ # Oldest supported and newest; tenuo ships one abi3 wheel, so no Rust build either way.
18
+ python: ["3.10", "3.13"]
19
+ steps:
20
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
21
+ with:
22
+ persist-credentials: false # tests run code from the PR; keep the token out of .git/config
23
+ - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
24
+ with:
25
+ python-version: ${{ matrix.python }}
26
+ - run: uv sync --locked # fails if uv.lock is stale against pyproject.toml
27
+ - run: uv run pytest -q
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ # examples/demo output when run from the repo root
5
+ /traces/
6
+ /proposal.yaml
7
+ /test_warrants.py
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.5
2
+ Name: warrantgen
3
+ Version: 0.1.0
4
+ Summary: Infer least-privilege Tenuo warrants from recorded agent tool calls
5
+ Project-URL: Repository, https://github.com/RajanChavada/warrantgen
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: tenuo<0.4,>=0.3.2
10
+ Provides-Extra: langchain
11
+ Requires-Dist: langchain-core>=0.3; extra == 'langchain'
12
+ Requires-Dist: langgraph>=0.3; extra == 'langchain'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # warrantgen
16
+
17
+ [![tests](https://github.com/RajanChavada/warrantgen/actions/workflows/tests.yml/badge.svg)](https://github.com/RajanChavada/warrantgen/actions/workflows/tests.yml)
18
+
19
+ Record what your AI agent actually does, then get the narrowest [Tenuo](https://github.com/tenuo-ai/tenuo) warrant
20
+ that still allows it: signed, per step, per sub-agent, with tests that keep it honest in CI.
21
+
22
+ Writing least-privilege warrants by hand is the slow part of adopting Tenuo. A real Temporal agent needed ~290 lines
23
+ of hand-written warrant, key and audit code. warrantgen infers the same constraints from recorded runs, and on that
24
+ agent's held-out runs it allows every legitimate call and denies every injected secret read.
25
+
26
+ Try it in five commands, no network or account: [examples/demo](https://github.com/RajanChavada/warrantgen/blob/main/examples/demo/README.md) records a small agent,
27
+ infers its warrants, and stops a prompt injection the agent fell for.
28
+
29
+ For actions that can't be undone, [examples/refund-agent](https://github.com/RajanChavada/warrantgen/blob/main/examples/refund-agent/README.md) caps refunds to recorded
30
+ behavior, gates each one behind a signed human approval, and runs 16 failure scenarios: injection, approval bypass,
31
+ expired approvals, malformed arguments, timeouts.
32
+
33
+ ## How it works
34
+
35
+ ```mermaid
36
+ flowchart TD
37
+ A["Your agent<br/>LangGraph or Temporal"] -- "Recorder<br/>(no warrant needed)" --> T[("traces.jsonl")]
38
+ T --> Q{"Quarantine runs that touched<br/>.env · .. · keys · metadata IPs"}
39
+ Q -- "clean runs" --> I["infer<br/>rules per step"]
40
+ I --> W["Signed warrant<br/>warrantgen.mint"]
41
+ I --> Y["tenuo-cli template<br/>warrantgen template"]
42
+ I --> C["Per-hop delegation chain<br/>warrantgen chain"]
43
+ I --> P["pytest tests<br/>warrantgen test"]
44
+ ```
45
+
46
+ 1. **Record** tool calls with a LangChain callback or Tenuo's Temporal `audit_callback`. Each call is tagged with its
47
+ run and its step (a LangGraph node path, or the warrant that checked it on Temporal).
48
+ 2. **Quarantine** any run that touched a secret file, a `..` path or a private host. It is never learned from.
49
+ 3. **Infer** one rule per argument from several runs: what's fixed, what changes per run, what's free text.
50
+ 4. **Use** the rules: mint a warrant, write a `tenuo-cli` template, mint a delegation chain, or generate tests.
51
+
52
+ ## What inference looks like
53
+
54
+ Rules inferred from 15 recorded runs of a real agent on 3 sites, next to the warrant its authors wrote by hand
55
+ (the `fetch.url` row comes from the LangGraph example):
56
+
57
+ | Argument | Recorded values | Inferred rule | Hand-written warrant |
58
+ |---|---|---|---|
59
+ | `repo` | one per run: `acme/site`, `northside/bakery-web`, ... | per-run value → `Exact` | `Exact(repo)` |
60
+ | `path` | this run's files | per-run list → `OneOf` | `OneOf(paths)` |
61
+ | `branch` | `fixagent/agent-20261018-014809`, ... | per-run value (or `Pattern("fixagent/*")`) | `Pattern("fixagent/*")` |
62
+ | `size` | 1 to 503 | `Range(0, 1000)` (rounded headroom) | `Range(max=20000)` |
63
+ | `text`, `message`, `body` | free text | `Wildcard` | `Wildcard` |
64
+ | `read_file.path` | files under `public/`, `web/` | under those folders, minus secrets and `..` | the same `All([...])` shape |
65
+ | `fetch.url` | pages on `docs.python.org/3/library/` | `UrlPattern(".../3/library/*")` | n/a |
66
+
67
+ Reads generalize to their folders or URL prefix (several hosts become `AnyOf` of one `UrlPattern` per host); writes keep
68
+ their exact files. Money-like arguments (`amount`, `price`, `cents`, ...) never get headroom.
69
+
70
+ ## Per-hop delegation chains
71
+
72
+ When a LangGraph supervisor hands work to sub-agents, `warrantgen chain` builds one warrant per hop from the recorded
73
+ node paths. Every child is minted from its parent through Tenuo's own delegation API, so Tenuo checks that each hop only
74
+ narrows.
75
+
76
+ ```mermaid
77
+ flowchart TD
78
+ R["root, signed by the issuer<br/>search · fetch · write_file"]
79
+ R --> T["team<br/>search · fetch"]
80
+ T --> S["team/researcher<br/>search · fetch under docs.python.org/3/library/"]
81
+ R --> W["writer<br/>write_file: this run's report only"]
82
+ S -.-x SD["write_file: denied"]
83
+ W -.-x WD["fetch: denied"]
84
+ ```
85
+
86
+ Tested under real `TenuoTool` enforcement with full chains: each sub-agent runs its recorded calls, and none can use a
87
+ sibling's tools. If Tenuo refuses to narrow an argument, it keeps its parent's constraint and `chain` says which.
88
+
89
+ ## Results on a real agent
90
+
91
+ The test agent is a Temporal workflow that opens pull requests to fix a website, minting one warrant per phase. 15
92
+ recorded runs: 3 sites × 5 behaviors, including a prompt injection that tries to read `.env` and
93
+ `../payments-api/.env`. Details in [examples/seo-agent](https://github.com/RajanChavada/warrantgen/blob/main/examples/seo-agent/README.md).
94
+
95
+ | Check | Result |
96
+ |---|---|
97
+ | Held-out replay (infer from 14 runs, replay the 15th through Tenuo's authorizer) | **186/186** legitimate calls allowed, **6/6** injected reads denied |
98
+ | Same replay with read paths deliberately unconstrained | 0/6 denied (the replay can fail) |
99
+ | Through `tenuo-cli` (`template validate` + `warrant issue`) | 41 templates issued, 87/87 calls allowed; 2 of 5 steps need template features proposed in [tenuo#959](https://github.com/tenuo-ai/tenuo/issues/959) |
100
+ | Generated tests against the agent's **hand-written** warrants | 40/44 at first: 4 places looser than recorded behavior. After pinning the branch: 43/44, `size` kept loose on purpose |
101
+
102
+ ## Quickstart
103
+
104
+ ```bash
105
+ pip install "warrantgen[langchain] @ git+https://github.com/RajanChavada/warrantgen"
106
+ ```
107
+
108
+ Record (several runs with different inputs: one run can't tell a fixed value from a per-run one):
109
+
110
+ ```python
111
+ # LangChain or LangGraph
112
+ from warrantgen.record_langchain import Recorder
113
+ graph.invoke(state, {"callbacks": [Recorder("traces.jsonl")]})
114
+
115
+ # Temporal, through Tenuo's plugin (dry_run=True with a broad warrant to observe)
116
+ from warrantgen.record_temporal import TemporalRecorder
117
+ TenuoPluginConfig(..., audit_callback=TemporalRecorder("traces.jsonl"))
118
+ ```
119
+
120
+ Then:
121
+
122
+ ```bash
123
+ warrantgen infer traces.jsonl # rules per step, plus quarantined runs
124
+ warrantgen template traces.jsonl --step write --set repo=acme/site --set paths=a.txt,b.txt --out write.yaml
125
+ tenuo-cli warrant issue --template write.yaml --holder agent
126
+ warrantgen chain traces.jsonl --from-run RUN # per-hop tree, minted and checked by Tenuo
127
+ warrantgen test traces.jsonl --out test_warrants.py # recorded calls allowed, near-misses denied
128
+ ```
129
+
130
+ In Python: `warrantgen.infer`, `warrantgen.mint`, `warrantgen.chain.mint_chains`. Pass `gates=["issue_refund"]` and
131
+ `approvers=[key.public_key]` to `mint` to require a signed approval on every call to those tools.
132
+
133
+ ### Test the warrants you ship
134
+
135
+ ```bash
136
+ warrantgen test traces.jsonl --warrant-for my_warrants:warrant_for --known-looser size --out tests/test_recorded_calls.py
137
+ ```
138
+
139
+ The generated file imports your `warrant_for(step, values, issuer, holder_public_key)` instead of warrantgen, so you can
140
+ commit it with only `tenuo` and `pytest` as dependencies. Each step's recorded calls must be allowed, and near-misses
141
+ must be denied: one argument just outside its rule, or a tool the step never used. `--known-looser` marks arguments you
142
+ loosen on purpose as strict expected failures, so tightening one later flags the stale mark.
143
+
144
+ ## Rules
145
+
146
+ | Rule | Inferred when | Tenuo constraint | Generated near-misses |
147
+ |---|---|---|---|
148
+ | exact | one value everywhere | `Exact` (numbers: `Range(n, n)`) | another value |
149
+ | per-run value | one value per run, different across runs | `Exact`, filled at mint time | another value |
150
+ | per-run list | a list that changes per run | `OneOf`, filled at mint time | a value not in the list |
151
+ | range | numbers | `Range`, rounded headroom | max + 1 |
152
+ | folders | path argument of a read tool | `All([folders, Not(secret), Not(..)])` | `.env`, `../`, another folder |
153
+ | URL prefix | URL argument of a read tool | `UrlPattern`, or `AnyOf` per host | another host, `..` climb |
154
+ | prefix | strings sharing a `/`-delimited prefix | `Pattern` | outside the prefix |
155
+ | subset | lists of items | `Subset` | an item outside the set |
156
+ | any | free text (whitespace or long) | `Wildcard` | none |
157
+
158
+ Override a guess with `--var ARG` (treat as per-run) or `--exact ARG` (pin it).
159
+
160
+ ## Status
161
+
162
+ Early and opinionated. Built and tested against `tenuo==0.3.2` and the local-cli stack (tenuo#942 to #952).
163
+ Limits and the Tenuo issues found along the way are tracked in [UPSTREAM.md](https://github.com/RajanChavada/warrantgen/blob/main/UPSTREAM.md).
164
+
165
+ ## License
166
+
167
+ Apache-2.0
@@ -0,0 +1,153 @@
1
+ # warrantgen
2
+
3
+ [![tests](https://github.com/RajanChavada/warrantgen/actions/workflows/tests.yml/badge.svg)](https://github.com/RajanChavada/warrantgen/actions/workflows/tests.yml)
4
+
5
+ Record what your AI agent actually does, then get the narrowest [Tenuo](https://github.com/tenuo-ai/tenuo) warrant
6
+ that still allows it: signed, per step, per sub-agent, with tests that keep it honest in CI.
7
+
8
+ Writing least-privilege warrants by hand is the slow part of adopting Tenuo. A real Temporal agent needed ~290 lines
9
+ of hand-written warrant, key and audit code. warrantgen infers the same constraints from recorded runs, and on that
10
+ agent's held-out runs it allows every legitimate call and denies every injected secret read.
11
+
12
+ Try it in five commands, no network or account: [examples/demo](https://github.com/RajanChavada/warrantgen/blob/main/examples/demo/README.md) records a small agent,
13
+ infers its warrants, and stops a prompt injection the agent fell for.
14
+
15
+ For actions that can't be undone, [examples/refund-agent](https://github.com/RajanChavada/warrantgen/blob/main/examples/refund-agent/README.md) caps refunds to recorded
16
+ behavior, gates each one behind a signed human approval, and runs 16 failure scenarios: injection, approval bypass,
17
+ expired approvals, malformed arguments, timeouts.
18
+
19
+ ## How it works
20
+
21
+ ```mermaid
22
+ flowchart TD
23
+ A["Your agent<br/>LangGraph or Temporal"] -- "Recorder<br/>(no warrant needed)" --> T[("traces.jsonl")]
24
+ T --> Q{"Quarantine runs that touched<br/>.env · .. · keys · metadata IPs"}
25
+ Q -- "clean runs" --> I["infer<br/>rules per step"]
26
+ I --> W["Signed warrant<br/>warrantgen.mint"]
27
+ I --> Y["tenuo-cli template<br/>warrantgen template"]
28
+ I --> C["Per-hop delegation chain<br/>warrantgen chain"]
29
+ I --> P["pytest tests<br/>warrantgen test"]
30
+ ```
31
+
32
+ 1. **Record** tool calls with a LangChain callback or Tenuo's Temporal `audit_callback`. Each call is tagged with its
33
+ run and its step (a LangGraph node path, or the warrant that checked it on Temporal).
34
+ 2. **Quarantine** any run that touched a secret file, a `..` path or a private host. It is never learned from.
35
+ 3. **Infer** one rule per argument from several runs: what's fixed, what changes per run, what's free text.
36
+ 4. **Use** the rules: mint a warrant, write a `tenuo-cli` template, mint a delegation chain, or generate tests.
37
+
38
+ ## What inference looks like
39
+
40
+ Rules inferred from 15 recorded runs of a real agent on 3 sites, next to the warrant its authors wrote by hand
41
+ (the `fetch.url` row comes from the LangGraph example):
42
+
43
+ | Argument | Recorded values | Inferred rule | Hand-written warrant |
44
+ |---|---|---|---|
45
+ | `repo` | one per run: `acme/site`, `northside/bakery-web`, ... | per-run value → `Exact` | `Exact(repo)` |
46
+ | `path` | this run's files | per-run list → `OneOf` | `OneOf(paths)` |
47
+ | `branch` | `fixagent/agent-20261018-014809`, ... | per-run value (or `Pattern("fixagent/*")`) | `Pattern("fixagent/*")` |
48
+ | `size` | 1 to 503 | `Range(0, 1000)` (rounded headroom) | `Range(max=20000)` |
49
+ | `text`, `message`, `body` | free text | `Wildcard` | `Wildcard` |
50
+ | `read_file.path` | files under `public/`, `web/` | under those folders, minus secrets and `..` | the same `All([...])` shape |
51
+ | `fetch.url` | pages on `docs.python.org/3/library/` | `UrlPattern(".../3/library/*")` | n/a |
52
+
53
+ Reads generalize to their folders or URL prefix (several hosts become `AnyOf` of one `UrlPattern` per host); writes keep
54
+ their exact files. Money-like arguments (`amount`, `price`, `cents`, ...) never get headroom.
55
+
56
+ ## Per-hop delegation chains
57
+
58
+ When a LangGraph supervisor hands work to sub-agents, `warrantgen chain` builds one warrant per hop from the recorded
59
+ node paths. Every child is minted from its parent through Tenuo's own delegation API, so Tenuo checks that each hop only
60
+ narrows.
61
+
62
+ ```mermaid
63
+ flowchart TD
64
+ R["root, signed by the issuer<br/>search · fetch · write_file"]
65
+ R --> T["team<br/>search · fetch"]
66
+ T --> S["team/researcher<br/>search · fetch under docs.python.org/3/library/"]
67
+ R --> W["writer<br/>write_file: this run's report only"]
68
+ S -.-x SD["write_file: denied"]
69
+ W -.-x WD["fetch: denied"]
70
+ ```
71
+
72
+ Tested under real `TenuoTool` enforcement with full chains: each sub-agent runs its recorded calls, and none can use a
73
+ sibling's tools. If Tenuo refuses to narrow an argument, it keeps its parent's constraint and `chain` says which.
74
+
75
+ ## Results on a real agent
76
+
77
+ The test agent is a Temporal workflow that opens pull requests to fix a website, minting one warrant per phase. 15
78
+ recorded runs: 3 sites × 5 behaviors, including a prompt injection that tries to read `.env` and
79
+ `../payments-api/.env`. Details in [examples/seo-agent](https://github.com/RajanChavada/warrantgen/blob/main/examples/seo-agent/README.md).
80
+
81
+ | Check | Result |
82
+ |---|---|
83
+ | Held-out replay (infer from 14 runs, replay the 15th through Tenuo's authorizer) | **186/186** legitimate calls allowed, **6/6** injected reads denied |
84
+ | Same replay with read paths deliberately unconstrained | 0/6 denied (the replay can fail) |
85
+ | Through `tenuo-cli` (`template validate` + `warrant issue`) | 41 templates issued, 87/87 calls allowed; 2 of 5 steps need template features proposed in [tenuo#959](https://github.com/tenuo-ai/tenuo/issues/959) |
86
+ | Generated tests against the agent's **hand-written** warrants | 40/44 at first: 4 places looser than recorded behavior. After pinning the branch: 43/44, `size` kept loose on purpose |
87
+
88
+ ## Quickstart
89
+
90
+ ```bash
91
+ pip install "warrantgen[langchain] @ git+https://github.com/RajanChavada/warrantgen"
92
+ ```
93
+
94
+ Record (several runs with different inputs: one run can't tell a fixed value from a per-run one):
95
+
96
+ ```python
97
+ # LangChain or LangGraph
98
+ from warrantgen.record_langchain import Recorder
99
+ graph.invoke(state, {"callbacks": [Recorder("traces.jsonl")]})
100
+
101
+ # Temporal, through Tenuo's plugin (dry_run=True with a broad warrant to observe)
102
+ from warrantgen.record_temporal import TemporalRecorder
103
+ TenuoPluginConfig(..., audit_callback=TemporalRecorder("traces.jsonl"))
104
+ ```
105
+
106
+ Then:
107
+
108
+ ```bash
109
+ warrantgen infer traces.jsonl # rules per step, plus quarantined runs
110
+ warrantgen template traces.jsonl --step write --set repo=acme/site --set paths=a.txt,b.txt --out write.yaml
111
+ tenuo-cli warrant issue --template write.yaml --holder agent
112
+ warrantgen chain traces.jsonl --from-run RUN # per-hop tree, minted and checked by Tenuo
113
+ warrantgen test traces.jsonl --out test_warrants.py # recorded calls allowed, near-misses denied
114
+ ```
115
+
116
+ In Python: `warrantgen.infer`, `warrantgen.mint`, `warrantgen.chain.mint_chains`. Pass `gates=["issue_refund"]` and
117
+ `approvers=[key.public_key]` to `mint` to require a signed approval on every call to those tools.
118
+
119
+ ### Test the warrants you ship
120
+
121
+ ```bash
122
+ warrantgen test traces.jsonl --warrant-for my_warrants:warrant_for --known-looser size --out tests/test_recorded_calls.py
123
+ ```
124
+
125
+ The generated file imports your `warrant_for(step, values, issuer, holder_public_key)` instead of warrantgen, so you can
126
+ commit it with only `tenuo` and `pytest` as dependencies. Each step's recorded calls must be allowed, and near-misses
127
+ must be denied: one argument just outside its rule, or a tool the step never used. `--known-looser` marks arguments you
128
+ loosen on purpose as strict expected failures, so tightening one later flags the stale mark.
129
+
130
+ ## Rules
131
+
132
+ | Rule | Inferred when | Tenuo constraint | Generated near-misses |
133
+ |---|---|---|---|
134
+ | exact | one value everywhere | `Exact` (numbers: `Range(n, n)`) | another value |
135
+ | per-run value | one value per run, different across runs | `Exact`, filled at mint time | another value |
136
+ | per-run list | a list that changes per run | `OneOf`, filled at mint time | a value not in the list |
137
+ | range | numbers | `Range`, rounded headroom | max + 1 |
138
+ | folders | path argument of a read tool | `All([folders, Not(secret), Not(..)])` | `.env`, `../`, another folder |
139
+ | URL prefix | URL argument of a read tool | `UrlPattern`, or `AnyOf` per host | another host, `..` climb |
140
+ | prefix | strings sharing a `/`-delimited prefix | `Pattern` | outside the prefix |
141
+ | subset | lists of items | `Subset` | an item outside the set |
142
+ | any | free text (whitespace or long) | `Wildcard` | none |
143
+
144
+ Override a guess with `--var ARG` (treat as per-run) or `--exact ARG` (pin it).
145
+
146
+ ## Status
147
+
148
+ Early and opinionated. Built and tested against `tenuo==0.3.2` and the local-cli stack (tenuo#942 to #952).
149
+ Limits and the Tenuo issues found along the way are tracked in [UPSTREAM.md](https://github.com/RajanChavada/warrantgen/blob/main/UPSTREAM.md).
150
+
151
+ ## License
152
+
153
+ Apache-2.0