agentperm 0.3.0__tar.gz → 0.4.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 (49) hide show
  1. agentperm-0.4.0/PKG-INFO +267 -0
  2. agentperm-0.4.0/README.md +206 -0
  3. agentperm-0.4.0/docs/README.md +43 -0
  4. {agentperm-0.3.0 → agentperm-0.4.0}/pyproject.toml +9 -29
  5. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/__init__.py +37 -3
  6. agentperm-0.4.0/src/agentperm/adapters/apply_patch.py +64 -0
  7. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/base.py +68 -0
  8. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/claude.py +23 -2
  9. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/codex.py +27 -1
  10. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/gemini.py +11 -2
  11. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/kiro.py +81 -3
  12. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/opencode.py +64 -6
  13. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/cli.py +241 -4
  14. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/domain.py +211 -45
  15. agentperm-0.4.0/src/agentperm/policy.py +428 -0
  16. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/rules.py +36 -16
  17. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/shell.py +24 -1
  18. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/shellpattern.py +16 -0
  19. agentperm-0.4.0/src/agentperm/templates/aws-read-only.jsonc +31 -0
  20. agentperm-0.4.0/src/agentperm/templates/docker-read-only.jsonc +14 -0
  21. agentperm-0.4.0/src/agentperm/templates/file-inspection.jsonc +26 -0
  22. agentperm-0.4.0/src/agentperm/templates/gh-read-only.jsonc +21 -0
  23. agentperm-0.4.0/src/agentperm/templates/git-read-only.jsonc +22 -0
  24. agentperm-0.4.0/src/agentperm/templates/packages-read-only.jsonc +24 -0
  25. agentperm-0.4.0/src/agentperm/templates/python-checks.jsonc +24 -0
  26. agentperm-0.4.0/src/agentperm/templates/safety-baseline.jsonc +29 -0
  27. agentperm-0.4.0/src/agentperm/validate.py +201 -0
  28. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_adapters.py +226 -33
  29. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_cli.py +84 -31
  30. agentperm-0.4.0/tests/test_opencode_guard.py +130 -0
  31. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_parser.py +14 -0
  32. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_policy.py +393 -34
  33. agentperm-0.4.0/tests/test_semantic_file_adapters.py +146 -0
  34. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_shellpattern.py +18 -2
  35. agentperm-0.4.0/tests/test_templates.py +235 -0
  36. agentperm-0.4.0/tests/test_validate.py +150 -0
  37. agentperm-0.3.0/PKG-INFO +0 -217
  38. agentperm-0.3.0/README.md +0 -158
  39. agentperm-0.3.0/src/agentperm/policy.py +0 -206
  40. {agentperm-0.3.0 → agentperm-0.4.0}/.gitignore +0 -0
  41. {agentperm-0.3.0 → agentperm-0.4.0}/LICENSE +0 -0
  42. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/adapters/__init__.py +0 -0
  43. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/errors.py +0 -0
  44. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/fileio.py +0 -0
  45. {agentperm-0.3.0 → agentperm-0.4.0}/src/agentperm/pythoncode.py +0 -0
  46. {agentperm-0.3.0 → agentperm-0.4.0}/tests/__init__.py +0 -0
  47. {agentperm-0.3.0 → agentperm-0.4.0}/tests/test_pythoncode.py +0 -0
  48. {agentperm-0.3.0 → agentperm-0.4.0}/zellij-plugin/README.md +0 -0
  49. {agentperm-0.3.0 → agentperm-0.4.0}/zellij-plugin/src/main.rs +0 -0
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentperm
3
+ Version: 0.4.0
4
+ Summary: Permission policy mediator for Claude Code, Codex, OpenCode, Gemini CLI, and Kiro.
5
+ Project-URL: Homepage, https://github.com/jacks0n/agentperm
6
+ Project-URL: Repository, https://github.com/jacks0n/agentperm
7
+ Project-URL: Documentation, https://github.com/jacks0n/agentperm/tree/main/docs
8
+ Project-URL: Changelog, https://github.com/jacks0n/agentperm/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/jacks0n/agentperm/issues
10
+ Author-email: Jackson Cooper <jackson@jacksonc.com>
11
+ License: MIT License
12
+
13
+ Copyright (c) 2026 Jackson Cooper
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all
23
+ copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ SOFTWARE.
32
+ License-File: LICENSE
33
+ Keywords: ai-agents,claude-code,codex-cli,coding-agent,gemini-cli,hooks,kiro,llm,opencode,permissions,policy-engine,tree-sitter-bash
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Environment :: Console
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: Intended Audience :: System Administrators
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Operating System :: MacOS
40
+ Classifier: Operating System :: POSIX :: Linux
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Classifier: Topic :: Security
46
+ Classifier: Topic :: Software Development
47
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
48
+ Classifier: Topic :: System :: Shells
49
+ Classifier: Topic :: System :: Systems Administration
50
+ Classifier: Typing :: Typed
51
+ Requires-Python: >=3.12
52
+ Requires-Dist: pyjson5<3,>=2.0
53
+ Requires-Dist: tomlkit<0.14,>=0.13
54
+ Requires-Dist: tree-sitter-bash<0.26,>=0.25
55
+ Requires-Dist: tree-sitter<0.26,>=0.25
56
+ Provides-Extra: dev
57
+ Requires-Dist: basedpyright>=1.13; extra == 'dev'
58
+ Requires-Dist: pytest>=8.0; extra == 'dev'
59
+ Requires-Dist: ruff>=0.6; extra == 'dev'
60
+ Description-Content-Type: text/markdown
61
+
62
+ # agentperm
63
+
64
+ **Stop approving the same safe command because a flag moved or it entered a pipe.**
65
+
66
+ agentperm gives [Claude Code](https://docs.anthropic.com/en/docs/claude-code),
67
+ [Codex CLI](https://github.com/openai/codex), [OpenCode](https://opencode.ai),
68
+ [Gemini CLI](https://github.com/google-gemini/gemini-cli), and [Kiro](https://kiro.dev) one local
69
+ permission policy. It parses shell programs, evaluates every command, and applies the strictest
70
+ result. You review intent once instead of maintaining five fragile string allowlists.
71
+
72
+ [![PyPI](https://img.shields.io/pypi/v/agentperm)](https://pypi.org/project/agentperm/)
73
+ [![Python](https://img.shields.io/pypi/pyversions/agentperm)](https://pypi.org/project/agentperm/)
74
+ [![CI](https://github.com/jacks0n/agentperm/actions/workflows/ci.yml/badge.svg)](https://github.com/jacks0n/agentperm/actions/workflows/ci.yml)
75
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jacks0n/agentperm/blob/main/LICENSE)
76
+
77
+ https://github.com/user-attachments/assets/9abcd24d-147c-4323-a1c3-970544e0d86a
78
+
79
+ [GIF fallback](https://raw.githubusercontent.com/jacks0n/agentperm/main/docs/media/demo.gif)
80
+
81
+ ## One command, fully understood
82
+
83
+ This policy allows read-only AWS inspection, `jq`, and `git status`:
84
+
85
+ ```jsonc
86
+ {
87
+ "version": 1,
88
+ "permissions": {
89
+ "allow": [
90
+ "Shell(aws values(--region, --profile) ec2 describe-* only(--region, --profile))",
91
+ "Shell(jq !-*)",
92
+ "Shell(git values(-C) status only(-C, --short))"
93
+ ]
94
+ }
95
+ }
96
+ ```
97
+
98
+ Now an agent can run this without a prompt:
99
+
100
+ ```sh
101
+ bash -lc 'aws --profile dev ec2 describe-instances --region ap-southeast-2 | jq ".Reservations[]" && git -C . status --short'
102
+ ```
103
+
104
+ agentperm unwraps `bash -lc`, splits the pipe and `&&`, and checks `aws`, `jq`, and `git`
105
+ independently. Move `--profile` or `--region` before or after the AWS subcommand, or use
106
+ `--region=value`: the same reviewed rule still matches.
107
+
108
+ The rule does not become broad just because it is flexible. Add `--endpoint-url`, change
109
+ `describe-*` to a mutating operation, or insert an unknown pipeline stage and the compound prompts.
110
+ A deny anywhere denies the whole operation.
111
+
112
+ That structural evaluation is the difference: agentperm understands pipelines, command and process
113
+ substitutions, redirects, executable paths, quoting, supported wrappers, flag clusters, and declared
114
+ flag values. It matches normalized commands—not one opaque shell string.
115
+
116
+ ## Try it
117
+
118
+ Requires Python 3.12+ on macOS or Linux.
119
+
120
+ ```sh
121
+ uv tool install agentperm # or: pipx install agentperm
122
+ agentperm install --dry-run && agentperm install
123
+ agentperm init
124
+ ```
125
+
126
+ `install --dry-run` shows every hook file before anything changes. `init` builds
127
+ `~/.agent-permissions.jsonc` from conservative starter templates. Check a decision without running
128
+ an agent:
129
+
130
+ ```console
131
+ $ agentperm why "git status | head -5"
132
+ allow — allow by rule 'Shell(git {status,log,diff,show,blame,shortlog,describe,reflog} values(-C))'
133
+ git status → allow (...)
134
+ head -5 → allow (...)
135
+ ```
136
+
137
+ Then use your agent normally. Existing native settings stay in place and continue to participate in
138
+ the host's permission flow. See [Getting started](docs/getting-started.md) for installation modes,
139
+ starter policies, and the first safe customization.
140
+
141
+ ## What one policy can express
142
+
143
+ - **Shell structure:** each command in pipes, chains, substitutions, control flow, and supported
144
+ wrappers is evaluated independently.
145
+ - **Useful permutations:** declare value-taking flags once; their order and `--flag=value` spelling
146
+ can vary without widening the rule.
147
+ - **Precise constraints:** alternate command paths, require or forbid flags, reject extra operands,
148
+ and allow only reviewed flags.
149
+ - **Semantic file controls:** write `Edit(src/**)` and `Write(dist/**)` once. Agent-specific edit,
150
+ write, notebook, and patch operations map to those capabilities.
151
+ - **Scoped tools:** match tools by name, prefix, URL domain, or normalized path, including cwd,
152
+ traversal, and existing symlinks.
153
+ - **Read-only inline Python:** `Python(readonly)` parses literal `python -c` and heredoc source with
154
+ Python's AST, allowing inspection while surfacing recognized mutations and dynamic effects.
155
+ - **Layered policy:** combine a global policy with directory policies. Global Deny is an immutable
156
+ floor; for Ask and Allow, the nearest matching policy wins, so a project can whitelist a global
157
+ prompt without weakening a deny.
158
+ - **Explainable decisions:** `why`, custom rule reasons, validation, and opt-in JSONL traces show why
159
+ a decision happened.
160
+ - **Portable setup:** install directly or through Rulesync, and import supported native policies.
161
+
162
+ The complete per-agent differences are in the [capability matrix](docs/capabilities.md).
163
+
164
+ ## Rules in 60 seconds
165
+
166
+ Rules live in `permissions.allow`, `permissions.ask`, or `permissions.deny`:
167
+
168
+ ```jsonc
169
+ {
170
+ "version": 1,
171
+ "permissions": {
172
+ "allow": [
173
+ "Shell(git {status,log,diff} !-*)",
174
+ "Shell(aws values(--region) s3 ls only(--region))",
175
+ "Read(src/**)",
176
+ "Python(readonly)"
177
+ ],
178
+ "ask": [
179
+ "Shell(git push)"
180
+ ],
181
+ "deny": [
182
+ {"Edit(generated/**)": {"reason": "Generated file; update its source instead."}},
183
+ {"Write(generated/**)": {"reason": "Generated file; update its source instead."}},
184
+ "Shell(git push --force)",
185
+ "Shell(sudo)"
186
+ ]
187
+ }
188
+ }
189
+ ```
190
+
191
+ Useful Shell forms:
192
+
193
+ | Form | Meaning |
194
+ |---|---|
195
+ | `{status,log,diff}` | one of these command-path tokens |
196
+ | `describe-*` | glob within one token |
197
+ | `values(--region)` | `--region` consumes the following token |
198
+ | `only(--region, --profile)` | reject every other flag |
199
+ | `!--force` | reject this flag |
200
+ | `!-*` | reject every flag |
201
+ | `!...` | reject trailing operands |
202
+
203
+ Run `agentperm validate` after editing. The [policy reference](docs/policy-reference.md) covers the
204
+ whole file format; the [Shell pattern DSL](docs/pattern-dsl.md) is the exact grammar and matching
205
+ specification.
206
+
207
+ ## How decisions compose
208
+
209
+ agentperm returns `allow`, `ask`, `deny`, or `no-opinion`. After policy-layer precedence selects a
210
+ verdict for each operation, the strictest result within a compound request wins:
211
+
212
+ ```text
213
+ deny > ask > allow > no-opinion
214
+ ```
215
+
216
+ An otherwise allowed pipeline with one unknown command becomes Ask. A multi-file patch with one
217
+ denied destination becomes Deny. `no-opinion` lets the host continue its native flow.
218
+
219
+ Policies load from `~/.agent-permissions.jsonc` and then from every directory between the filesystem
220
+ root and the command's working directory. Deny matches across every layer. For Ask and Allow, the
221
+ nearest policy with a matching rule wins; within one file, Ask precedes Allow. A cloned repository
222
+ can therefore bring its own allows, so review checked-in policy files like `.envrc` or
223
+ `.vscode/tasks.json`.
224
+
225
+ ## Security boundary
226
+
227
+ agentperm is a **permission intent layer, not a sandbox**. It does not contain processes, prove what
228
+ an allowed program will do, or see execution paths a host does not send through hooks. Host bypass
229
+ mode can bypass agentperm entirely. Use OS isolation when containment matters and read
230
+ [SECURITY.md](SECURITY.md) before treating policies as a security control.
231
+
232
+ - It adds decisions to native permission flows; it does not replace host settings.
233
+ - It does not configure or isolate MCP servers.
234
+ - Directory policies are not trust-gated: a cloned repository can add allows and override global
235
+ Ask rules, though it cannot weaken any Deny.
236
+ - Shell and Python analysis classify reviewed intent; they do not prove program behavior.
237
+
238
+ Traces are also diagnostic—not a production audit system. They are off by default, may contain raw
239
+ commands and secrets, and have no built-in redaction, rotation, retention, or tamper protection.
240
+ See [CLI: diagnostic traces](docs/cli.md#diagnostic-traces).
241
+
242
+ There is no SQL syntax analyzer today. SQL clients can be constrained with Shell rules, but
243
+ agentperm does not distinguish `SELECT` from mutating SQL inside a query string.
244
+
245
+ ## Zellij pane bypass
246
+
247
+ The bundled [Zellij plugin](zellij-plugin/) adds a per-pane “skip prompts” toggle. It turns Ask and
248
+ NoOpinion into Allow for that pane while preserving Deny, making it narrower than a host-wide
249
+ “dangerously skip permissions” mode.
250
+
251
+ ## Documentation
252
+
253
+ - [Getting started](docs/getting-started.md) — install, initialize, and verify a policy.
254
+ - [Capability matrix](docs/capabilities.md) — exact coverage and behavior by agent.
255
+ - [Policy reference](docs/policy-reference.md) — schema, semantic tools, hierarchy, and redirects.
256
+ - [Shell pattern DSL](docs/pattern-dsl.md) — complete matching grammar and limitations.
257
+ - [CLI reference](docs/cli.md) — commands, hook installation, traces, and exit behavior.
258
+ - [Troubleshooting](docs/troubleshooting.md) — symptom-led diagnosis and fixes.
259
+ - [Architecture](docs/architecture.md) and [adapter notes](docs/adapters.md) — contributor internals.
260
+ - [Changelog](CHANGELOG.md) and [contributing guide](CONTRIBUTING.md) — releases and development.
261
+
262
+ `agentperm uninstall` removes only hooks written by agentperm; policy files remain yours. Then remove
263
+ the package with `uv tool uninstall agentperm` or `pipx uninstall agentperm`.
264
+
265
+ ## License
266
+
267
+ MIT
@@ -0,0 +1,206 @@
1
+ # agentperm
2
+
3
+ **Stop approving the same safe command because a flag moved or it entered a pipe.**
4
+
5
+ agentperm gives [Claude Code](https://docs.anthropic.com/en/docs/claude-code),
6
+ [Codex CLI](https://github.com/openai/codex), [OpenCode](https://opencode.ai),
7
+ [Gemini CLI](https://github.com/google-gemini/gemini-cli), and [Kiro](https://kiro.dev) one local
8
+ permission policy. It parses shell programs, evaluates every command, and applies the strictest
9
+ result. You review intent once instead of maintaining five fragile string allowlists.
10
+
11
+ [![PyPI](https://img.shields.io/pypi/v/agentperm)](https://pypi.org/project/agentperm/)
12
+ [![Python](https://img.shields.io/pypi/pyversions/agentperm)](https://pypi.org/project/agentperm/)
13
+ [![CI](https://github.com/jacks0n/agentperm/actions/workflows/ci.yml/badge.svg)](https://github.com/jacks0n/agentperm/actions/workflows/ci.yml)
14
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jacks0n/agentperm/blob/main/LICENSE)
15
+
16
+ https://github.com/user-attachments/assets/9abcd24d-147c-4323-a1c3-970544e0d86a
17
+
18
+ [GIF fallback](https://raw.githubusercontent.com/jacks0n/agentperm/main/docs/media/demo.gif)
19
+
20
+ ## One command, fully understood
21
+
22
+ This policy allows read-only AWS inspection, `jq`, and `git status`:
23
+
24
+ ```jsonc
25
+ {
26
+ "version": 1,
27
+ "permissions": {
28
+ "allow": [
29
+ "Shell(aws values(--region, --profile) ec2 describe-* only(--region, --profile))",
30
+ "Shell(jq !-*)",
31
+ "Shell(git values(-C) status only(-C, --short))"
32
+ ]
33
+ }
34
+ }
35
+ ```
36
+
37
+ Now an agent can run this without a prompt:
38
+
39
+ ```sh
40
+ bash -lc 'aws --profile dev ec2 describe-instances --region ap-southeast-2 | jq ".Reservations[]" && git -C . status --short'
41
+ ```
42
+
43
+ agentperm unwraps `bash -lc`, splits the pipe and `&&`, and checks `aws`, `jq`, and `git`
44
+ independently. Move `--profile` or `--region` before or after the AWS subcommand, or use
45
+ `--region=value`: the same reviewed rule still matches.
46
+
47
+ The rule does not become broad just because it is flexible. Add `--endpoint-url`, change
48
+ `describe-*` to a mutating operation, or insert an unknown pipeline stage and the compound prompts.
49
+ A deny anywhere denies the whole operation.
50
+
51
+ That structural evaluation is the difference: agentperm understands pipelines, command and process
52
+ substitutions, redirects, executable paths, quoting, supported wrappers, flag clusters, and declared
53
+ flag values. It matches normalized commands—not one opaque shell string.
54
+
55
+ ## Try it
56
+
57
+ Requires Python 3.12+ on macOS or Linux.
58
+
59
+ ```sh
60
+ uv tool install agentperm # or: pipx install agentperm
61
+ agentperm install --dry-run && agentperm install
62
+ agentperm init
63
+ ```
64
+
65
+ `install --dry-run` shows every hook file before anything changes. `init` builds
66
+ `~/.agent-permissions.jsonc` from conservative starter templates. Check a decision without running
67
+ an agent:
68
+
69
+ ```console
70
+ $ agentperm why "git status | head -5"
71
+ allow — allow by rule 'Shell(git {status,log,diff,show,blame,shortlog,describe,reflog} values(-C))'
72
+ git status → allow (...)
73
+ head -5 → allow (...)
74
+ ```
75
+
76
+ Then use your agent normally. Existing native settings stay in place and continue to participate in
77
+ the host's permission flow. See [Getting started](docs/getting-started.md) for installation modes,
78
+ starter policies, and the first safe customization.
79
+
80
+ ## What one policy can express
81
+
82
+ - **Shell structure:** each command in pipes, chains, substitutions, control flow, and supported
83
+ wrappers is evaluated independently.
84
+ - **Useful permutations:** declare value-taking flags once; their order and `--flag=value` spelling
85
+ can vary without widening the rule.
86
+ - **Precise constraints:** alternate command paths, require or forbid flags, reject extra operands,
87
+ and allow only reviewed flags.
88
+ - **Semantic file controls:** write `Edit(src/**)` and `Write(dist/**)` once. Agent-specific edit,
89
+ write, notebook, and patch operations map to those capabilities.
90
+ - **Scoped tools:** match tools by name, prefix, URL domain, or normalized path, including cwd,
91
+ traversal, and existing symlinks.
92
+ - **Read-only inline Python:** `Python(readonly)` parses literal `python -c` and heredoc source with
93
+ Python's AST, allowing inspection while surfacing recognized mutations and dynamic effects.
94
+ - **Layered policy:** combine a global policy with directory policies. Global Deny is an immutable
95
+ floor; for Ask and Allow, the nearest matching policy wins, so a project can whitelist a global
96
+ prompt without weakening a deny.
97
+ - **Explainable decisions:** `why`, custom rule reasons, validation, and opt-in JSONL traces show why
98
+ a decision happened.
99
+ - **Portable setup:** install directly or through Rulesync, and import supported native policies.
100
+
101
+ The complete per-agent differences are in the [capability matrix](docs/capabilities.md).
102
+
103
+ ## Rules in 60 seconds
104
+
105
+ Rules live in `permissions.allow`, `permissions.ask`, or `permissions.deny`:
106
+
107
+ ```jsonc
108
+ {
109
+ "version": 1,
110
+ "permissions": {
111
+ "allow": [
112
+ "Shell(git {status,log,diff} !-*)",
113
+ "Shell(aws values(--region) s3 ls only(--region))",
114
+ "Read(src/**)",
115
+ "Python(readonly)"
116
+ ],
117
+ "ask": [
118
+ "Shell(git push)"
119
+ ],
120
+ "deny": [
121
+ {"Edit(generated/**)": {"reason": "Generated file; update its source instead."}},
122
+ {"Write(generated/**)": {"reason": "Generated file; update its source instead."}},
123
+ "Shell(git push --force)",
124
+ "Shell(sudo)"
125
+ ]
126
+ }
127
+ }
128
+ ```
129
+
130
+ Useful Shell forms:
131
+
132
+ | Form | Meaning |
133
+ |---|---|
134
+ | `{status,log,diff}` | one of these command-path tokens |
135
+ | `describe-*` | glob within one token |
136
+ | `values(--region)` | `--region` consumes the following token |
137
+ | `only(--region, --profile)` | reject every other flag |
138
+ | `!--force` | reject this flag |
139
+ | `!-*` | reject every flag |
140
+ | `!...` | reject trailing operands |
141
+
142
+ Run `agentperm validate` after editing. The [policy reference](docs/policy-reference.md) covers the
143
+ whole file format; the [Shell pattern DSL](docs/pattern-dsl.md) is the exact grammar and matching
144
+ specification.
145
+
146
+ ## How decisions compose
147
+
148
+ agentperm returns `allow`, `ask`, `deny`, or `no-opinion`. After policy-layer precedence selects a
149
+ verdict for each operation, the strictest result within a compound request wins:
150
+
151
+ ```text
152
+ deny > ask > allow > no-opinion
153
+ ```
154
+
155
+ An otherwise allowed pipeline with one unknown command becomes Ask. A multi-file patch with one
156
+ denied destination becomes Deny. `no-opinion` lets the host continue its native flow.
157
+
158
+ Policies load from `~/.agent-permissions.jsonc` and then from every directory between the filesystem
159
+ root and the command's working directory. Deny matches across every layer. For Ask and Allow, the
160
+ nearest policy with a matching rule wins; within one file, Ask precedes Allow. A cloned repository
161
+ can therefore bring its own allows, so review checked-in policy files like `.envrc` or
162
+ `.vscode/tasks.json`.
163
+
164
+ ## Security boundary
165
+
166
+ agentperm is a **permission intent layer, not a sandbox**. It does not contain processes, prove what
167
+ an allowed program will do, or see execution paths a host does not send through hooks. Host bypass
168
+ mode can bypass agentperm entirely. Use OS isolation when containment matters and read
169
+ [SECURITY.md](SECURITY.md) before treating policies as a security control.
170
+
171
+ - It adds decisions to native permission flows; it does not replace host settings.
172
+ - It does not configure or isolate MCP servers.
173
+ - Directory policies are not trust-gated: a cloned repository can add allows and override global
174
+ Ask rules, though it cannot weaken any Deny.
175
+ - Shell and Python analysis classify reviewed intent; they do not prove program behavior.
176
+
177
+ Traces are also diagnostic—not a production audit system. They are off by default, may contain raw
178
+ commands and secrets, and have no built-in redaction, rotation, retention, or tamper protection.
179
+ See [CLI: diagnostic traces](docs/cli.md#diagnostic-traces).
180
+
181
+ There is no SQL syntax analyzer today. SQL clients can be constrained with Shell rules, but
182
+ agentperm does not distinguish `SELECT` from mutating SQL inside a query string.
183
+
184
+ ## Zellij pane bypass
185
+
186
+ The bundled [Zellij plugin](zellij-plugin/) adds a per-pane “skip prompts” toggle. It turns Ask and
187
+ NoOpinion into Allow for that pane while preserving Deny, making it narrower than a host-wide
188
+ “dangerously skip permissions” mode.
189
+
190
+ ## Documentation
191
+
192
+ - [Getting started](docs/getting-started.md) — install, initialize, and verify a policy.
193
+ - [Capability matrix](docs/capabilities.md) — exact coverage and behavior by agent.
194
+ - [Policy reference](docs/policy-reference.md) — schema, semantic tools, hierarchy, and redirects.
195
+ - [Shell pattern DSL](docs/pattern-dsl.md) — complete matching grammar and limitations.
196
+ - [CLI reference](docs/cli.md) — commands, hook installation, traces, and exit behavior.
197
+ - [Troubleshooting](docs/troubleshooting.md) — symptom-led diagnosis and fixes.
198
+ - [Architecture](docs/architecture.md) and [adapter notes](docs/adapters.md) — contributor internals.
199
+ - [Changelog](CHANGELOG.md) and [contributing guide](CONTRIBUTING.md) — releases and development.
200
+
201
+ `agentperm uninstall` removes only hooks written by agentperm; policy files remain yours. Then remove
202
+ the package with `uv tool uninstall agentperm` or `pipx uninstall agentperm`.
203
+
204
+ ## License
205
+
206
+ MIT
@@ -0,0 +1,43 @@
1
+ # agentperm documentation
2
+
3
+ Use this page to find the shortest path to the answer you need. The README explains why agentperm
4
+ exists; these docs separate tasks, exact behavior, and maintainer internals so each fact has one
5
+ authoritative home.
6
+
7
+ ## I want to…
8
+
9
+ | Goal | Start here |
10
+ |---|---|
11
+ | Install agentperm and remove my first prompt | [Getting started](getting-started.md) |
12
+ | See what each supported agent can enforce | [Capability matrix](capabilities.md) |
13
+ | Write or organize a policy | [Policy reference](policy-reference.md) |
14
+ | Match flags, permutations, pipes, and wrappers | [Shell pattern DSL](pattern-dsl.md) |
15
+ | Understand a decision or inspect a trace | [`why`](cli.md#why) and [diagnostic traces](cli.md#diagnostic-traces) |
16
+ | Fix prompting, hook, policy, or parsing problems | [Troubleshooting](troubleshooting.md) |
17
+ | Assess the security boundary | [Security model](../SECURITY.md) |
18
+ | Understand or extend the implementation | [Architecture](architecture.md), then [adapter notes](adapters.md) |
19
+
20
+ ## Reading layers
21
+
22
+ - **Evaluate and try:** [project README](../README.md) and [getting started](getting-started.md).
23
+ - **Operate:** [CLI reference](cli.md), [capability matrix](capabilities.md), and
24
+ [troubleshooting](troubleshooting.md).
25
+ - **Specify:** [policy reference](policy-reference.md) and [Shell pattern DSL](pattern-dsl.md).
26
+ - **Maintain:** [architecture](architecture.md), [adapter notes](adapters.md), and
27
+ [contributing](../CONTRIBUTING.md).
28
+
29
+ ## Terminology
30
+
31
+ | Term | Meaning |
32
+ |---|---|
33
+ | **policy** | The merged global and directory `.agent-permissions.jsonc` files used for a request. |
34
+ | **rule** | One allow, ask, or deny entry: `Shell(...)`, legacy `Bash(...)`, a named/scoped tool, a structured Bash option rule, or `Python(readonly)`. |
35
+ | **segment** | One executable command extracted from shell source. `a | b && c` has three. |
36
+ | **request** | A shell operation, semantic tool operation, compound operation, or rejected operation produced by an adapter. |
37
+ | **verdict** | `allow`, `ask`, `deny`, or `no-opinion`, plus a rationale. |
38
+
39
+ ## Documentation contract
40
+
41
+ Guides optimize for completing a task; references define exact behavior. When a guide and reference
42
+ appear to disagree, treat that as a documentation bug. Implementation tests and the Unreleased
43
+ changelog are checked during documentation updates so shipped behavior stays authoritative.
@@ -4,47 +4,25 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agentperm"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Permission policy mediator for Claude Code, Codex, OpenCode, Gemini CLI, and Kiro."
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
11
11
  requires-python = ">=3.12"
12
12
  authors = [{ name = "Jackson Cooper", email = "jackson@jacksonc.com" }]
13
13
  keywords = [
14
- "ai",
15
- "ai-agent",
16
- "ai-agents",
17
- "ai-tools",
18
- "agent",
19
- "agentic",
20
- "agentic-ai",
21
- "agentic-tools",
22
- "ai-coding-assistant",
23
- "anthropic",
24
- "tree-sitter",
25
- "tree-sitter-bash",
26
- "claude",
27
14
  "claude-code",
28
- "codex",
29
15
  "codex-cli",
30
- "coding-agent",
31
- "coding-assistant",
32
- "developer-tools",
33
- "gemini",
34
16
  "gemini-cli",
35
- "hooks",
36
- "kiro",
37
- "llm",
38
- "llm-agent",
39
- "llm-tools",
40
- "mcp",
41
- "mediator",
42
17
  "opencode",
43
- "openai",
18
+ "kiro",
19
+ "coding-agent",
20
+ "ai-agents",
44
21
  "permissions",
45
- "policy",
46
22
  "policy-engine",
47
- "shell",
23
+ "hooks",
24
+ "tree-sitter-bash",
25
+ "llm",
48
26
  ]
49
27
  classifiers = [
50
28
  "Development Status :: 4 - Beta",
@@ -75,6 +53,8 @@ dependencies = [
75
53
  [project.urls]
76
54
  Homepage = "https://github.com/jacks0n/agentperm"
77
55
  Repository = "https://github.com/jacks0n/agentperm"
56
+ Documentation = "https://github.com/jacks0n/agentperm/tree/main/docs"
57
+ Changelog = "https://github.com/jacks0n/agentperm/blob/main/CHANGELOG.md"
78
58
  Issues = "https://github.com/jacks0n/agentperm/issues"
79
59
 
80
60
  [project.scripts]
@@ -5,9 +5,10 @@ Package layout:
5
5
  agentperm.shell — Tree-sitter Bash → Pipeline
6
6
  agentperm.pythoncode — shallow AST analysis for inline Python
7
7
  agentperm.rules — string/dict ↔ Rule
8
- agentperm.policy — file ↔ Policy
8
+ agentperm.policy — file ↔ Policy, bundled templates
9
+ agentperm.validate — policy linting
9
10
  agentperm.adapters — AgentAdapter ABC + Claude/Codex/Opencode/Gemini/Kiro
10
- agentperm.cli — import, check, edit, install
11
+ agentperm.cli — install, uninstall, import, init, validate, why, check, edit
11
12
  """
12
13
 
13
14
  from __future__ import annotations
@@ -20,6 +21,7 @@ from .domain import (
20
21
  AgentName,
21
22
  BashCommand,
22
23
  BashOption,
24
+ CompoundRequest,
23
25
  Decision,
24
26
  InstallMode,
25
27
  JsonArray,
@@ -31,6 +33,7 @@ from .domain import (
31
33
  PythonCallPolicy,
32
34
  PythonReadonly,
33
35
  RedirectionPolicy,
36
+ RejectedRequest,
34
37
  Request,
35
38
  Rule,
36
39
  Segment,
@@ -42,12 +45,30 @@ from .domain import (
42
45
  narrow_json,
43
46
  )
44
47
  from .errors import PolicyError
45
- from .policy import PolicyFile, git_toplevel, load_policy_file, merged_policy, save_policy_file, write_default_policy
48
+ from .policy import (
49
+ DEFAULT_TEMPLATES,
50
+ PolicyFile,
51
+ Template,
52
+ TemplateMerge,
53
+ available_templates,
54
+ existing_policy_paths,
55
+ git_toplevel,
56
+ load_policy_file,
57
+ load_template,
58
+ merge_templates_into,
59
+ merged_policy,
60
+ parse_policy_text,
61
+ render_templates,
62
+ save_policy_file,
63
+ write_default_policy,
64
+ )
46
65
  from .rules import parse_rule
47
66
  from .shell import parse_pipeline
67
+ from .validate import Finding, validate_policy_file, validate_policy_text
48
68
 
49
69
  __all__ = [
50
70
  "ADAPTERS",
71
+ "DEFAULT_TEMPLATES",
51
72
  "POLICY_FILENAME",
52
73
  "AgentAdapter",
53
74
  "AgentName",
@@ -55,7 +76,9 @@ __all__ = [
55
76
  "BashOption",
56
77
  "ClaudeAdapter",
57
78
  "CodexAdapter",
79
+ "CompoundRequest",
58
80
  "Decision",
81
+ "Finding",
59
82
  "GeminiAdapter",
60
83
  "InstallMode",
61
84
  "JsonArray",
@@ -71,24 +94,35 @@ __all__ = [
71
94
  "PythonCallPolicy",
72
95
  "PythonReadonly",
73
96
  "RedirectionPolicy",
97
+ "RejectedRequest",
74
98
  "Request",
75
99
  "Rule",
76
100
  "Segment",
77
101
  "ShellPattern",
78
102
  "ShellRequest",
103
+ "Template",
104
+ "TemplateMerge",
79
105
  "ToolRequest",
80
106
  "Verdict",
81
107
  "agentperm_bypass_dir",
82
108
  "aggregate",
109
+ "available_templates",
83
110
  "coerce_for_pane_bypass",
84
111
  "coerce_for_permission_mode",
112
+ "existing_policy_paths",
85
113
  "git_toplevel",
86
114
  "load_policy_file",
115
+ "load_template",
87
116
  "main",
117
+ "merge_templates_into",
88
118
  "merged_policy",
89
119
  "narrow_json",
90
120
  "parse_pipeline",
121
+ "parse_policy_text",
91
122
  "parse_rule",
123
+ "render_templates",
92
124
  "save_policy_file",
125
+ "validate_policy_file",
126
+ "validate_policy_text",
93
127
  "write_default_policy",
94
128
  ]