anchor-gateway 0.3.1__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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ Use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Lauren Flipo
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: anchor-gateway
3
+ Version: 0.3.1
4
+ Summary: ANCHOR middleware: one-line governance for agent tools (allow/deny/ask, every verdict with a receipt)
5
+ Author: Lauren Flipo
6
+ License-Expression: Apache-2.0
7
+ Keywords: ai-agents,governance,policy,guardrails,capability-security
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Security
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: langchain
21
+ Requires-Dist: langchain-core; extra == "langchain"
22
+ Provides-Extra: openai-agents
23
+ Requires-Dist: openai-agents; extra == "openai-agents"
24
+ Provides-Extra: crewai
25
+ Requires-Dist: crewai; extra == "crewai"
26
+ Dynamic: license-file
27
+
28
+ # ANCHOR Middleware — Phase 3
29
+
30
+ One-line governance for agent tools: every tool call is judged by the real
31
+ ANCHOR v1 guardian before it runs. Verdicts: **allow / deny / ask**, every one
32
+ logged with a receipt. Native shims for LangChain, OpenAI Agents SDK, and
33
+ CrewAI; human approval over CLI or webhook; four versioned constitution packs;
34
+ a live verdict dashboard served by the daemon; ships as the `anchor-gateway`
35
+ package with an `anchor` CLI.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install anchor-gateway # core: daemon + client (stdlib-only, zero deps)
41
+ pip install "anchor-gateway[langchain]"
42
+ pip install "anchor-gateway[openai-agents]"
43
+ pip install "anchor-gateway[crewai]"
44
+ ```
45
+
46
+ (Not yet published to PyPI — see `PUBLISH_CHECKLIST.md`. Until then, install
47
+ from this directory: `pip install -e .`)
48
+
49
+ Phase 2 was proven against langchain-core 1.6.6, openai-agents 0.20.0,
50
+ crewai 1.15.23 — the pinned set in `REQUIREMENTS.md`
51
+ (`pip check` clean; do not blindly upgrade openai-agents/crewai).
52
+
53
+ ## Constitution packs
54
+
55
+ | Pack | For | Allow | Ask | Deny |
56
+ |---|---|---|---|---|
57
+ | `code-agent` | coding agents in one project dir | reads, listings, read-only cmds | writes, deletes, other cmds | traversal, exfil binaries, shell metachars |
58
+ | `browser-agent` | web-browsing agents | allowlisted-domain nav, clicks, reads | unknown domains, downloads/uploads, forms, credential typing | private IPs, `169.254.169.254`, `file://`, traversal |
59
+ | `support-agent` | customer-support agents | ticket/order reads, drafts, canned-template sends | freeform sends, refunds > $100 | bulk export (unknown tool), non-numeric amounts |
60
+ | `data-agent` | data agents | aggregated PII-free queries, table reads | row-level or PII queries, capped exports | prod writes (`write_table`, `drop_table`), over-cap exports |
61
+
62
+ ```bash
63
+ anchor run --constitution constitutions/browser-agent.yaml
64
+ # or: anchor-gateway --port 8471 --constitution constitutions/data-agent.yaml
65
+ # anchor init --constitution support-agent (scaffolds a project with that pack)
66
+ ```
67
+
68
+ Writing your own pack: `docs/CONSTITUTION_AUTHORING.md`. What the governor
69
+ guarantees (and doesn't): `docs/SECURITY_MODEL.md`.
70
+
71
+ ## Verdict dashboard
72
+
73
+ The daemon serves a live dashboard — no new services, no new ports:
74
+
75
+ ```bash
76
+ anchor run & # daemon on :8471
77
+ # open http://127.0.0.1:8471/dashboard
78
+ ```
79
+
80
+ Chain-status banner (the trust anchor), allow/deny/ask counts, a filterable
81
+ verdict table, and an "adversarial spotlight" of denied attacks. The page is
82
+ one self-contained file (`gateway/dashboard.html`); JS reads the existing
83
+ `GET /v1/verdicts`. Fleet/multi-daemon aggregation is explicitly out of scope
84
+ (needs daemon auth + a collector — a Phase 4 decision).
85
+
86
+ ## Run it
87
+
88
+ ```bash
89
+ anchor init # scaffolds ./anchor.yaml + ./constitutions/code-agent.yaml
90
+ anchor run # starts the policy daemon (localhost only, :8471)
91
+ # or: anchor-gateway --port 8471 --constitution constitutions/code-agent.yaml
92
+ ```
93
+
94
+ ## In your agent code
95
+
96
+ ```python
97
+ import anchor
98
+ anchor.configure(agent_id="my-agent",
99
+ approval_callback=my_approver) # (tool, params, reason, pending_id) -> bool
100
+
101
+ @anchor.govern(tool="read_file")
102
+ def read_file(path): ...
103
+
104
+ result = read_file("notes.txt")
105
+ # -> GovernedResult(value=..., capability_id=..., via="direct")
106
+ # Denied calls raise anchor.GovernedDeny and NEVER execute.
107
+ # Unreachable daemon raises GovernedDeny(fail_closed=True).
108
+ ```
109
+
110
+ `anchor.wrap_tool(fn, tool=...)` wraps an existing callable without decorator
111
+ syntax. `anchor.decide_tool_call(tool, params)` judges without executing
112
+ (the path the framework shims use).
113
+
114
+ ### Framework shims
115
+
116
+ ```python
117
+ # LangChain — wrap any BaseTool; the agent sees the same name/description.
118
+ from anchor.integrations.langchain import govern_tool
119
+ tool = govern_tool(my_structured_tool)
120
+ tool.invoke({"path": "notes.txt"}) # allow -> runs; deny -> GovernedDeny
121
+
122
+ # OpenAI Agents SDK — a native tool input guardrail.
123
+ from agents import function_tool
124
+ from anchor.integrations.openai_agents import attach_anchor_guardrail, governed_function_tool
125
+
126
+ @function_tool
127
+ def read_file(path: str) -> str: ...
128
+ attach_anchor_guardrail(read_file) # or: @governed_function_tool
129
+
130
+ # CrewAI — wrap any BaseTool.
131
+ from anchor.integrations.crewai import govern_tool
132
+ tool = govern_tool(my_crewai_tool)
133
+ tool.run(path="notes.txt")
134
+ ```
135
+
136
+ Shim contract (all three): **allow** → the tool runs, receipt
137
+ (`capability_id`) attached to the decision; **deny** → the tool never runs;
138
+ **ask** → the configured approval callback runs (bounded by
139
+ `approval_timeout`), rejection or timeout denies fail-closed.
140
+
141
+ ## ASK approval channels
142
+
143
+ `anchor/approvals.py` ships three callbacks:
144
+
145
+ - `cli_approver` — interactive terminal prompt (`approve? [y/N]`); EOF/Ctrl-C
146
+ or any non-yes denies. Default priority; webhook is the option.
147
+ - `webhook_approver(url)` — POSTs `{pending_id, tool, params, reason}`.
148
+ Sync mode: the webhook answers `200 {"approved": bool}`. Async mode: it
149
+ answers `202` and resolves later through the daemon's `POST /v1/resolve`;
150
+ the client polls `GET /v1/pending/<pending_id>` until resolved or the
151
+ timeout. Unreachable webhook → deny (fail closed).
152
+ - `auto_approver(True/False)` — canned answers for tests only.
153
+
154
+ Resolve is **idempotent**: the daemon records each `pending_id`'s outcome, so
155
+ a second `POST /v1/resolve` (client after webhook, or a retry) returns the
156
+ recorded receipt instead of minting twice. First resolution wins on races.
157
+
158
+ ## CLI reference
159
+
160
+ - `anchor init [--constitution code-agent] [--dir .]` — scaffold a project.
161
+ - `anchor run [--port PORT]` — start the daemon from `./anchor.yaml`
162
+ (falls back to the packaged constitution when the project one is missing).
163
+ - `anchor-gateway [--port 8471] [--constitution ...]` — the daemon directly.
164
+ - Env: `ANCHOR_GATEWAY_PORT`, `ANCHOR_PROJECT_DIR`, `ANCHOR_VERDICTS_LOG`
165
+ (proofs use the last one to keep the production log clean).
166
+
167
+ ## Prove it
168
+
169
+ ```bash
170
+ ~/workspace/anchor-v1/.venv/bin/python proof.py # Phase 1: PROOF: PASS
171
+ ~/workspace/anchor-v1/.venv/bin/python proof_phase2.py # Phase 2: PROOF2: PASS
172
+ ~/workspace/anchor-v1/.venv/bin/python proof_phase3.py # Phase 3: PROOF3: PASS
173
+ ```
174
+
175
+ Phase 2 drives its own daemon on :8472 with an isolated verdicts log: per-shim
176
+ allow+deny through the real daemon (13 checks: LangChain, OpenAI Agents
177
+ guardrail, CrewAI), CLI ask→approve→allow and ask→timeout→deny, webhook
178
+ ask→resolve→allow, `anchor init` + `anchor run` end to end, and a final
179
+ `chain_ok` on the proof log. Full model-driven `Runner`/`kickoff` runs need
180
+ API keys and are out of scope; the shims are proven at the interception
181
+ boundary, which is where governance lives.
182
+
183
+ Phase 3 drives one daemon per constitution pack (browser, support, data) on
184
+ :8473 with isolated logs: per-pack allow+deny+ask through the real daemon
185
+ (35 checks incl. ask→resolve→allow round trips), each log `chain_ok`.
186
+ The dashboard is proven separately: `GET /dashboard` → 200 `text/html`,
187
+ all markers present, verdicts live from `/v1/verdicts`.
188
+
189
+ Evidence: `verdicts.log` (hash-chained; `GET /v1/verdicts` reports `chain_ok`).
190
+
191
+ ## What's real vs. simplified (no padding)
192
+
193
+ - **Real:** `AcsGuardian.handle_event` on `TOOL_CALL_PROPOSED` with the
194
+ constitution as `decision_fn`; real COSE one-use capability mint on allow
195
+ (verified + registered, `capability_id` is the receipt); the guardian's
196
+ native ASK flow (`pending_id` → `resolve_pending`) with an idempotent daemon
197
+ receipt layer on top (no double-spend); fail-closed on every error path,
198
+ including daemon-unreachable and hung approvers.
199
+ - **Simplified:** the daemon mints to its own holder identity — holder-of-key
200
+ proofs and PEP consumption belong to an execution plane, and this layer
201
+ judges without executing (by design). The verdict log lives in one file;
202
+ multi-daemon / fleet sync is a Phase 4 decision, not a dashboard feature.
203
+ - **Conservative edges (fail-closed, documented):** the generalized
204
+ path-substring rule scans *all* params, so e.g. a code string mentioning
205
+ `/etc/passwd` is denied; `$` and backticks are denied in `run_cmd` args but
206
+ allowed in file content (inert data); network policy denies unparseable
207
+ URLs and non-absolute `url_params`; credential-shaped param keys always ask.
208
+ The YAML parser is a stdlib subset (block + flow lists, folded `>` blocks,
209
+ comments) — constitutions needing more wait for full PyYAML.
210
+
211
+ ## Layout
212
+
213
+ - `gateway/server.py` — stdlib-only daemon (`/v1/decide`, `/v1/resolve`,
214
+ `/v1/pending/<id>`, `/v1/verdicts`, `/v1/health`, `/dashboard`)
215
+ - `gateway/dashboard.html` — self-contained verdict dashboard page
216
+ - `gateway/constitution.py` — YAML-subset loader + three-tier decision_fn
217
+ (tiers, path-substring rule, `network:` URL policy, `tool_rules:`)
218
+ - `constitutions/` — `code-agent`, `browser-agent`, `support-agent`,
219
+ `data-agent` policy packs (versioned)
220
+ - `anchor/client.py` — `govern`, `wrap_tool`, `decide_tool_call`,
221
+ `GovernedDeny`, `GovernedResult`, `Decision`
222
+ - `anchor/approvals.py` — `cli_approver`, `webhook_approver`, `auto_approver`
223
+ - `anchor/integrations/` — `langchain`, `openai_agents`, `crewai` shims
224
+ - `anchor/cli.py` — the `anchor` CLI (`init`, `run`)
225
+ - `docs/` — `CONSTITUTION_AUTHORING.md`, `SECURITY_MODEL.md`
226
+ - `proof.py`, `proof_phase2.py`, `proof_phase3.py`, `proof-project/`
227
+ - `PUBLISH_CHECKLIST.md`, `REQUIREMENTS.md`, `CHALLENGE.md` (launch held)
@@ -0,0 +1,200 @@
1
+ # ANCHOR Middleware — Phase 3
2
+
3
+ One-line governance for agent tools: every tool call is judged by the real
4
+ ANCHOR v1 guardian before it runs. Verdicts: **allow / deny / ask**, every one
5
+ logged with a receipt. Native shims for LangChain, OpenAI Agents SDK, and
6
+ CrewAI; human approval over CLI or webhook; four versioned constitution packs;
7
+ a live verdict dashboard served by the daemon; ships as the `anchor-gateway`
8
+ package with an `anchor` CLI.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install anchor-gateway # core: daemon + client (stdlib-only, zero deps)
14
+ pip install "anchor-gateway[langchain]"
15
+ pip install "anchor-gateway[openai-agents]"
16
+ pip install "anchor-gateway[crewai]"
17
+ ```
18
+
19
+ (Not yet published to PyPI — see `PUBLISH_CHECKLIST.md`. Until then, install
20
+ from this directory: `pip install -e .`)
21
+
22
+ Phase 2 was proven against langchain-core 1.6.6, openai-agents 0.20.0,
23
+ crewai 1.15.23 — the pinned set in `REQUIREMENTS.md`
24
+ (`pip check` clean; do not blindly upgrade openai-agents/crewai).
25
+
26
+ ## Constitution packs
27
+
28
+ | Pack | For | Allow | Ask | Deny |
29
+ |---|---|---|---|---|
30
+ | `code-agent` | coding agents in one project dir | reads, listings, read-only cmds | writes, deletes, other cmds | traversal, exfil binaries, shell metachars |
31
+ | `browser-agent` | web-browsing agents | allowlisted-domain nav, clicks, reads | unknown domains, downloads/uploads, forms, credential typing | private IPs, `169.254.169.254`, `file://`, traversal |
32
+ | `support-agent` | customer-support agents | ticket/order reads, drafts, canned-template sends | freeform sends, refunds > $100 | bulk export (unknown tool), non-numeric amounts |
33
+ | `data-agent` | data agents | aggregated PII-free queries, table reads | row-level or PII queries, capped exports | prod writes (`write_table`, `drop_table`), over-cap exports |
34
+
35
+ ```bash
36
+ anchor run --constitution constitutions/browser-agent.yaml
37
+ # or: anchor-gateway --port 8471 --constitution constitutions/data-agent.yaml
38
+ # anchor init --constitution support-agent (scaffolds a project with that pack)
39
+ ```
40
+
41
+ Writing your own pack: `docs/CONSTITUTION_AUTHORING.md`. What the governor
42
+ guarantees (and doesn't): `docs/SECURITY_MODEL.md`.
43
+
44
+ ## Verdict dashboard
45
+
46
+ The daemon serves a live dashboard — no new services, no new ports:
47
+
48
+ ```bash
49
+ anchor run & # daemon on :8471
50
+ # open http://127.0.0.1:8471/dashboard
51
+ ```
52
+
53
+ Chain-status banner (the trust anchor), allow/deny/ask counts, a filterable
54
+ verdict table, and an "adversarial spotlight" of denied attacks. The page is
55
+ one self-contained file (`gateway/dashboard.html`); JS reads the existing
56
+ `GET /v1/verdicts`. Fleet/multi-daemon aggregation is explicitly out of scope
57
+ (needs daemon auth + a collector — a Phase 4 decision).
58
+
59
+ ## Run it
60
+
61
+ ```bash
62
+ anchor init # scaffolds ./anchor.yaml + ./constitutions/code-agent.yaml
63
+ anchor run # starts the policy daemon (localhost only, :8471)
64
+ # or: anchor-gateway --port 8471 --constitution constitutions/code-agent.yaml
65
+ ```
66
+
67
+ ## In your agent code
68
+
69
+ ```python
70
+ import anchor
71
+ anchor.configure(agent_id="my-agent",
72
+ approval_callback=my_approver) # (tool, params, reason, pending_id) -> bool
73
+
74
+ @anchor.govern(tool="read_file")
75
+ def read_file(path): ...
76
+
77
+ result = read_file("notes.txt")
78
+ # -> GovernedResult(value=..., capability_id=..., via="direct")
79
+ # Denied calls raise anchor.GovernedDeny and NEVER execute.
80
+ # Unreachable daemon raises GovernedDeny(fail_closed=True).
81
+ ```
82
+
83
+ `anchor.wrap_tool(fn, tool=...)` wraps an existing callable without decorator
84
+ syntax. `anchor.decide_tool_call(tool, params)` judges without executing
85
+ (the path the framework shims use).
86
+
87
+ ### Framework shims
88
+
89
+ ```python
90
+ # LangChain — wrap any BaseTool; the agent sees the same name/description.
91
+ from anchor.integrations.langchain import govern_tool
92
+ tool = govern_tool(my_structured_tool)
93
+ tool.invoke({"path": "notes.txt"}) # allow -> runs; deny -> GovernedDeny
94
+
95
+ # OpenAI Agents SDK — a native tool input guardrail.
96
+ from agents import function_tool
97
+ from anchor.integrations.openai_agents import attach_anchor_guardrail, governed_function_tool
98
+
99
+ @function_tool
100
+ def read_file(path: str) -> str: ...
101
+ attach_anchor_guardrail(read_file) # or: @governed_function_tool
102
+
103
+ # CrewAI — wrap any BaseTool.
104
+ from anchor.integrations.crewai import govern_tool
105
+ tool = govern_tool(my_crewai_tool)
106
+ tool.run(path="notes.txt")
107
+ ```
108
+
109
+ Shim contract (all three): **allow** → the tool runs, receipt
110
+ (`capability_id`) attached to the decision; **deny** → the tool never runs;
111
+ **ask** → the configured approval callback runs (bounded by
112
+ `approval_timeout`), rejection or timeout denies fail-closed.
113
+
114
+ ## ASK approval channels
115
+
116
+ `anchor/approvals.py` ships three callbacks:
117
+
118
+ - `cli_approver` — interactive terminal prompt (`approve? [y/N]`); EOF/Ctrl-C
119
+ or any non-yes denies. Default priority; webhook is the option.
120
+ - `webhook_approver(url)` — POSTs `{pending_id, tool, params, reason}`.
121
+ Sync mode: the webhook answers `200 {"approved": bool}`. Async mode: it
122
+ answers `202` and resolves later through the daemon's `POST /v1/resolve`;
123
+ the client polls `GET /v1/pending/<pending_id>` until resolved or the
124
+ timeout. Unreachable webhook → deny (fail closed).
125
+ - `auto_approver(True/False)` — canned answers for tests only.
126
+
127
+ Resolve is **idempotent**: the daemon records each `pending_id`'s outcome, so
128
+ a second `POST /v1/resolve` (client after webhook, or a retry) returns the
129
+ recorded receipt instead of minting twice. First resolution wins on races.
130
+
131
+ ## CLI reference
132
+
133
+ - `anchor init [--constitution code-agent] [--dir .]` — scaffold a project.
134
+ - `anchor run [--port PORT]` — start the daemon from `./anchor.yaml`
135
+ (falls back to the packaged constitution when the project one is missing).
136
+ - `anchor-gateway [--port 8471] [--constitution ...]` — the daemon directly.
137
+ - Env: `ANCHOR_GATEWAY_PORT`, `ANCHOR_PROJECT_DIR`, `ANCHOR_VERDICTS_LOG`
138
+ (proofs use the last one to keep the production log clean).
139
+
140
+ ## Prove it
141
+
142
+ ```bash
143
+ ~/workspace/anchor-v1/.venv/bin/python proof.py # Phase 1: PROOF: PASS
144
+ ~/workspace/anchor-v1/.venv/bin/python proof_phase2.py # Phase 2: PROOF2: PASS
145
+ ~/workspace/anchor-v1/.venv/bin/python proof_phase3.py # Phase 3: PROOF3: PASS
146
+ ```
147
+
148
+ Phase 2 drives its own daemon on :8472 with an isolated verdicts log: per-shim
149
+ allow+deny through the real daemon (13 checks: LangChain, OpenAI Agents
150
+ guardrail, CrewAI), CLI ask→approve→allow and ask→timeout→deny, webhook
151
+ ask→resolve→allow, `anchor init` + `anchor run` end to end, and a final
152
+ `chain_ok` on the proof log. Full model-driven `Runner`/`kickoff` runs need
153
+ API keys and are out of scope; the shims are proven at the interception
154
+ boundary, which is where governance lives.
155
+
156
+ Phase 3 drives one daemon per constitution pack (browser, support, data) on
157
+ :8473 with isolated logs: per-pack allow+deny+ask through the real daemon
158
+ (35 checks incl. ask→resolve→allow round trips), each log `chain_ok`.
159
+ The dashboard is proven separately: `GET /dashboard` → 200 `text/html`,
160
+ all markers present, verdicts live from `/v1/verdicts`.
161
+
162
+ Evidence: `verdicts.log` (hash-chained; `GET /v1/verdicts` reports `chain_ok`).
163
+
164
+ ## What's real vs. simplified (no padding)
165
+
166
+ - **Real:** `AcsGuardian.handle_event` on `TOOL_CALL_PROPOSED` with the
167
+ constitution as `decision_fn`; real COSE one-use capability mint on allow
168
+ (verified + registered, `capability_id` is the receipt); the guardian's
169
+ native ASK flow (`pending_id` → `resolve_pending`) with an idempotent daemon
170
+ receipt layer on top (no double-spend); fail-closed on every error path,
171
+ including daemon-unreachable and hung approvers.
172
+ - **Simplified:** the daemon mints to its own holder identity — holder-of-key
173
+ proofs and PEP consumption belong to an execution plane, and this layer
174
+ judges without executing (by design). The verdict log lives in one file;
175
+ multi-daemon / fleet sync is a Phase 4 decision, not a dashboard feature.
176
+ - **Conservative edges (fail-closed, documented):** the generalized
177
+ path-substring rule scans *all* params, so e.g. a code string mentioning
178
+ `/etc/passwd` is denied; `$` and backticks are denied in `run_cmd` args but
179
+ allowed in file content (inert data); network policy denies unparseable
180
+ URLs and non-absolute `url_params`; credential-shaped param keys always ask.
181
+ The YAML parser is a stdlib subset (block + flow lists, folded `>` blocks,
182
+ comments) — constitutions needing more wait for full PyYAML.
183
+
184
+ ## Layout
185
+
186
+ - `gateway/server.py` — stdlib-only daemon (`/v1/decide`, `/v1/resolve`,
187
+ `/v1/pending/<id>`, `/v1/verdicts`, `/v1/health`, `/dashboard`)
188
+ - `gateway/dashboard.html` — self-contained verdict dashboard page
189
+ - `gateway/constitution.py` — YAML-subset loader + three-tier decision_fn
190
+ (tiers, path-substring rule, `network:` URL policy, `tool_rules:`)
191
+ - `constitutions/` — `code-agent`, `browser-agent`, `support-agent`,
192
+ `data-agent` policy packs (versioned)
193
+ - `anchor/client.py` — `govern`, `wrap_tool`, `decide_tool_call`,
194
+ `GovernedDeny`, `GovernedResult`, `Decision`
195
+ - `anchor/approvals.py` — `cli_approver`, `webhook_approver`, `auto_approver`
196
+ - `anchor/integrations/` — `langchain`, `openai_agents`, `crewai` shims
197
+ - `anchor/cli.py` — the `anchor` CLI (`init`, `run`)
198
+ - `docs/` — `CONSTITUTION_AUTHORING.md`, `SECURITY_MODEL.md`
199
+ - `proof.py`, `proof_phase2.py`, `proof_phase3.py`, `proof-project/`
200
+ - `PUBLISH_CHECKLIST.md`, `REQUIREMENTS.md`, `CHALLENGE.md` (launch held)
@@ -0,0 +1,19 @@
1
+ from .client import (
2
+ Decision,
3
+ GovernedDeny,
4
+ GovernedResult,
5
+ configure,
6
+ decide_tool_call,
7
+ govern,
8
+ wrap_tool,
9
+ )
10
+
11
+ __all__ = [
12
+ "Decision",
13
+ "configure",
14
+ "decide_tool_call",
15
+ "govern",
16
+ "wrap_tool",
17
+ "GovernedDeny",
18
+ "GovernedResult",
19
+ ]